title: Access Session attribute on jstl
body: <p>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 of a standard or custom action". What could be wrong, am I accessing it incorrectly? The following is the code snippet.</p>
  
  <hr>
  
  <p>Servlet:</p>
  
  <pre><code>protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  
      HttpSession session = request.getSession(); 
      session.setAttribute("Questions", getQuestion());
      System.out.println(session.getAttribute("Questions"));
      RequestDispatcher req = request.getRequestDispatcher("DisplayQuestions.jsp");
      req.forward(request, response);
  }
  
  private QuestionBookDAO getQuestion(){
      QuestionBookDAO q = new QuestionBookDAO();
      q.setQuestion("First Question");
      q.setQuestionPaperID(100210);
      q.setSubTopic("Java");
      q.setTopic("Threads");
      return q;
  }
  </code></pre>
  
  <p>I am able to set the session attribute successfully. But when I try to access the same in my jsp file (below), I am getting a runtime error</p>
  
  <pre><code>    &lt;jsp:useBean id="Questions" type="com.cet.evaluation.QuestionBook" scope="session"&gt;
      &lt;jsp:getProperty property="Questions" name="questionPaperID"/&gt;
      &lt;jsp:getProperty property="Questions" name="question"/&gt;
      &lt;/jsp:useBean&gt;
  </code></pre>
  
  <p>The bean QuestionBook contains two private variables <strong>questionPaperID</strong> and <strong>question</strong>
  I run the application on Tomcat and below is the error thrown.</p>
  
  <pre><code>type Exception report
  
  message 
  
      description The server encountered an internal error () that prevented it from fulfilling this request.
  
      exception 
  
      org.apache.jasper.JasperException: /DisplayQuestions.jsp(15,11) jsp:attribute must be the subelement of a standard or custom action
          org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
          org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
          org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:88)
          org.apache.jasper.compiler.Parser.parseStandardAction(Parser.java:1160)
          org.apache.jasper.compiler.Parser.parseElements(Parser.java:1461)
          org.apache.jasper.compiler.Parser.parseBody(Parser.java:1670)
          org.apache.jasper.compiler.Parser.parseOptionalBody(Parser.java:1020)
              ....
  </code></pre>