title: How can you pass in a value from a database on one jsp page to another jsp page?
body: <p>On one page I displayed a table from my database and the user chooses a department. Based on that option the next page will display the items within that department. Is there a way that you can pass the department id from page 1 to page 2's SQL query so that you can display only that department's items?</p>
  
  <p>The only thing I am aware of is printing the department number on the page with</p>
  
  <pre><code>    &lt;%=session.getAttribute("deptid")&gt;;
  </code></pre>
  
  <p>First Page: </p>
  
  <pre><code>    &lt;table&gt;
      &lt;tr&gt;
          &lt;td&gt;Select Department&lt;/td&gt;
          &lt;td&gt;&lt;select name="deptid"&gt;
          &lt;option value="select"&gt;select&lt;/option&gt;
          &lt;%
              while(rs.next()){
                  String deptid= rs.getString("deptid");
          %&gt;
          &lt;option value=&lt;%=deptid%&gt;&gt;&lt;%=deptid%&gt;&lt;/option&gt;
          &lt;%
              }
      }catch(SQLException sqe){
          out.println("showcourses"+sqe);
      }
          %&gt;
          &lt;/select&gt;&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>Here's a connector JSP page</p>
  
  <pre><code>    String sql = "select * from courses where deptid=?";
  
  String deptid= request.getParameter("deptid");
  
  if(!(deptid.equalsIgnoreCase("select"))){
      try{
          Class.forName(driverName);
          con = DriverManager.getConnection(url, user, dbpsw);
          ps = con.prepareStatement(sql);
          ps.setString(1, majorid);
          rs = ps.executeQuery();
          if(rs.next()){ 
              userdeptid = rs.getString("deptid");
              System.out.println(userdeptid );
  
              if(deptid.equals(userdeptid )){
                  session.setAttribute("deptid",userdeptid);
                  response.sendRedirect("showitems.jsp");
              }
          }else
              response.sendRedirect("error.jsp");
          rs.close();
          ps.close(); 
      } catch(SQLException sqe){
          out.println(sqe);
      } 
  }
  </code></pre>
  
  <p>%></p>