Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Want to access ArrayList of objects into an object from jstl  RSS feed

 
shivay veer sharma
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

I have an object user which have arrayList of images he have
images itself is a object of image type which have name size
and all so i have the user object set into session
and i want to print a table of images with its detail.

class user
{
ArrayList<image> images = new Arraylist();
geter and setter
}

class image
{
String name;
String size;
getr and seter
}

in servelet
I have set and the object to the session named user
in HTML
<c:forEach var="images1" items="${user.images}" >
<%-- <c:forEach var="images1" items="${user.images}" > --%>
<tr>
<td>${images1.name }</td>
<td>${images1.size }</td>
</tr>

</c:forEach>

And i am getting following error
HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: /WEB-INF/images.jsp(138,6) According to TLD or attribute directive in tag file, attribute items does not accept any expressions
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:148)
org.apache.jasper.compiler.Validator$ValidateVisitor.checkXmlAttributes(Validator.java:1209)
org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:846)
org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1530)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2411)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2417)
org.apache.jasper.compiler.Node$Root.accept(Node.java:495)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2361)
org.apache.jasper.compiler.Validator.validateExDirectives(Validator.java:1763)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:198)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:354)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:334)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:321)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
user.Controller.doPost(Controller.java:104)
user.Controller.doGet(Controller.java:40)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.35 logs.

Apache Tomcat/6.0.35

with scriptlets this is working
HttpSession se = request.getSession();
User user;
user = (User)se.getAttribute("user");
ArrayList<Image> l = user.getImages();
if(l != null)
{
int sizeOfList = l.size();
for(int i=0 ; i<sizeOfList ; i++)
{
out.println("<tr><td>"+l.get(i).getName()+"</td><td>"+l.get(i).getSize()+"</td></tr>");
}
}

please help me ASAP...

Regards
Shivay Veer Sharma
 
Stefan Evans
Bartender
Posts: 1836
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make sure you have JSTL1.1 or better and change your import of the taglibrary from:

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
to
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>


Explanation:
You see this message when you use the JSTL1.0 tld for the core library. A long time ago (in Servlet 2.3/JSP1.2 era) ${expr} were not understood by the servlet container, and so JSTL1.0 specifically forbade using runtime expressions as it was responsible for interpreting the EL.

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!