Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi All,

I am developing a small web application in Eclipse. I have trouble showing up Arraylist in JSP.
Whenever i try to list all users in database on web page page, it takes lot of time to load home page and then server gives me some OutOfMemory error as

Exception in thread "ContainerBackgroundProcessor[StandardEngine[Catalina]]" Exception in thread "http-bio-8080-exec-3" java.lang.OutOfMemoryError: Java heap space
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:116)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1374)
at org.apache.catalina.core.StandardWrapper.backgroundProcess(StandardWrapper.java:704)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1530)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1540)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1540)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1540)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1519)
at java.lang.Thread.run(Unknown Source)
java.lang.OutOfMemoryError: Java heap space


In my Home.java servlet, what i want to do is, when user clicks on ListMembers link, the site should take him to ListUser.jsp. But code is getting stuck here somewhere.
Here is my servlet code:

Java
public class Home extends HttpServlet {
	private static final long serialVersionUID = 1L;
       String varshowusername;
       
       List<User> userslist = new ArrayList<User>();
       //Iterator<User> item = userslist.iterator();
       Saveuserdata objsaveuserdata = new Saveuserdata(); //DAO obj which has listusers method          that fetches list of user names from DB and returns Arraylist of User
    
    public Home() {
        super();
        
    }

	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		varshowusername=(String) request.getSession().getAttribute("CurrentLoggedInUser");
		userslist= objsaveuserdata.getallusers();
		request.getSession().setAttribute("UserList", userslist);
		
		PrintWriter out = response.getWriter();
		
		
		out.println("<HTML>"); 
	    out.println("<TITLE>Home</TITLE>");
	    out.println("<HEAD>");
	    out.println("<link rel=stylesheet type=text/css href=/mypractice/css/mystyle1.css></link>");
	    out.println("</HEAD>");
	    out.println("<BODY>");
	    out.println("<p>"); 
	    out.println("Welcome! This is your Home Page");
	    out.print("<br>");
	    out.print(varshowusername);
	    out.print("<br>");
	  /*  out.println("<table border='2'>");
	    out.print("<tr>");
	    out.println("<td>");
	    out.println("Name");
	    out.print("<tr>");
	    while(item.hasNext()){
	    	
	    	out.print("<td>");
	    	out.print(users.getname());
	    	out.print("</td>");
	    	item.next();
	    }
	    out.print("</tr>");
	    out.println("</table>"); */
	    out.print("<a href='ListUsers.jsp'>List Members</a>");
	    request.getRequestDispatcher("ListUsers.jsp").forward(request,response);
	    out.print("<a href='Logout'>Log Out</a>");
	    out.println("</p>");
	    out.println("</BODY>");
	    out.println("</HTML>");
	    
	}


Here is my JSP code:

HTML
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
   <table border=1>
       
            <tr>
                <td>User Name</td>
              
            </tr>
        
        <tbody>
            <c:forEach items="${userslist}" var="users">
                <tr>
                    <td><c:out value="${users.name}" /></td>
                    
                </tr>
            </c:forEach>
        </tbody>
    </table>
</body>
</html>


Also, though i have added the jstl1.2.jar to my /WEB-INF/lib, the Eclipse still shows me, Unknown Tag (C:ForEach)

Please help me!!!
I am trying to learn servlets and JSPs.
Also, if you feel some modifications are needed in code, please do suggest!
Thank you in adv.
Posted
Comments
SanketAB 18-Feb-13 9:50am    
Anybody has solution for this?
Please help me!!!
jhez25 8-Mar-13 22:14pm    
you try to find codes in this links..
http://www.facebook.com/pages/Java-Server-Pages/106898082682605?fref=ts&rf=115011585181566
SanketAB 12-Mar-13 4:58am    
Thanks J for your reply.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900