protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=UTF-8");
        String name = request.getParameter("name").toString();
        ArrayList a = new ArrayList();
        int y =a.size();

        Connection con = null;
        String url = "jdbc:mysql://localhost:3306/";
        String db = "test";
        String driver = "com.mysql.jdbc.Driver";
        String user = "root";
        String pass = null;
        try{
          Class.forName(driver).newInstance();
          con = DriverManager.getConnection(url+db, user, pass);
          try{
            Statement st = con.createStatement();
            ResultSet res = st.executeQuery("SELECT employee FROM  employ ");
     
            while (res.next()) {
             String s = res.getString("employee");
              int len=name.length();
             String x= s.substring(0,len);
             
            
                          if(x.equalsIgnoreCase(name))
             {
             
            	System.out.println(s);
            	a.add(s);
             }
            }
            	
            if(a.size()<1)
            {
            	response.sendRedirect("noemp.jsp");
            }
            else
            response.sendRedirect("empresult.jsp");  
            con.close();
          }
          
          catch (SQLException s){
            System.out.println("SQL code does not execute.");
          }    
        }
        catch (Exception e){
          e.printStackTrace();
        }
		// TODO Auto-generated method stub
	}   	  	    
}

how do i access array list "a" in my jsp page?????????????

Recommended Answers

All 3 Replies

I hope this piece of doPost() method will be part of the servlet and you not planning to stick it into JSP.
If you want access something from Java in the JSP view you need to import appropriate library in something like this

<%@ page import="java.util.ArrayList"%>

ok here goes... i have an arraylist in my servlet page

and i want to access it on my jsp

so i used session.setAttribute

but i get an error message on my eclipse ide that says

session cannot be resolved...

please help..........

Yes, the above library import will do it as long you correctly handled session request. Check this post for some guidelines. It is still not finished, but it may answer many of your questions

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.