Access Session attribute on jstl

前端 未结 2 1667
醉酒成梦
醉酒成梦 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 22:50

    You don't need the jsp:useBean to set the model if you already have a controller which prepared the model.

    Just access it plain by EL:

    ${Questions.questionPaperID}

    ${Questions.question}

    or by JSTL tag if you'd like to HTML-escape the values or when you're still working on legacy Servlet 2.3 containers or older when EL wasn't supported in template text yet:

    See also:

    • Our Servlets wiki page

    Unrelated to the problem, the normal practice is by the way to start attribute name with a lowercase, like you do with normal variable names.

    session.setAttribute("questions", questions);
    

    and alter EL accordingly to use ${questions}.

    Also note that you don't have any JSTL tag in your code. It's all plain JSP.

提交回复
热议问题