Access Session attribute on jstl

前端 未结 2 1660
醉酒成梦
醉酒成梦 2020-12-08 22:21

I am trying to access a session attribute from a jsp page which is set and dispatched by a servlet, but I am getting the error message \"jsp:attribute must be the subelement

2条回答
  •  不思量自难忘°
    2020-12-08 23:10

    You should definitely avoid using tags. They're relics from the past and should always be avoided now.

    Use the JSTL.

    Now, wether you use the JSTL or any other tag library, accessing to a bean property needs your bean to have this property. A property is not a private instance variable. It's an information accessible via a public getter (and setter, if the property is writable). To access the questionPaperID property, you thus need to have a

    public SomeType getQuestionPaperID() {
        //...
    }
    

    method in your bean.

    Once you have that, you can display the value of this property using this code :

    
    

    or, to specifically target the session scoped attributes (in case of conflicts between scopes) :

    
    

    Finally, I encourage you to name scope attributes as Java variables : starting with a lowercase letter.

提交回复
热议问题