title: How can I pass a string value to another jsp page using session.setAttribute ("", table) why it's not executing? "select * from " + table + "";?
body: <p>Why mysql query string query ="select * from " + table + "";` is not working the table name is coming from another jsp page.</p>
  
  <p>And why session. setAttribute ("", "table");` is not working to import string from jsp to jsp?</p>
  
  <p>I have two jsp file in my code one is for selection of table for username and password to get login the file name is statement.jsp and other file statement is for showing data in a table that is selected in statement3.jsp. I want to use table string in another jsp page to show that table.</p>
  
  <p><strong>error</strong></p>
  
  <pre><code>   String query ="select * from " + table + ""; //for selection of table
  
     session.setAttribute("", "table");  //To pass String table from statement.jsp to statement3.jsp to show table. 
  </code></pre>
  
  <p><strong><a href="https://i.stack.imgur.com/1zAt8.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1zAt8.jpg" alt="enter image description here"></a>statement3.jsp</strong>    </p>
  
  <pre><code>  &lt;%  
       ResultSet rs = null;
       session.setAttribute("", "table"); 
  
       String query ="select * from " + table + "";
  
       rs=st.executeQuery(query);
   %&gt; 
  </code></pre>
  
  <hr>
  
  <p><strong>statement.jsp</strong>     </p>
  
  <pre><code>&lt;% 
   ResultSet rs = null;
   String name=request.getParameter("username");
   String abc=request.getParameter("password");       
  
   String gender = request.getParameter("gender");
  
   if (gender != null) {
   String table = gender.equals("teacher") ? "teacher2" : "student";
  
   out.println(table);  
  
   String query ="select * from " + table + " where username='"+name+"' AND password='"+abc+"'";
   rs=st.executeQuery(query); 
   out.println(rs);
   if(rs.next()) 
   {
     response.sendRedirect("statement3.jsp");
   }
     else
  {
    response.sendRedirect("index.jsp");
   }}
  %&gt;
  </code></pre>
  
  <p><code>Stacktrace:
      org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:93)
      org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
      org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:435)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:298)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:277)
      org.apache.jasper.compiler.Compiler.compile(Compiler.java:265)
      org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:564)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:302)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:729)</code></p>