Win a copy of Microservices in Action this week in the Web Services forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

How to pass static list from servlet to JSP?  RSS feed

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
register.jsp



Register.java



Employee.java



 
Rancher
Posts: 506
15
Java Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
servlet:


jsp:
 
Rohan Kesharwani
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Prasad Saya wrote:servlet:


jsp:




still error
and employee is variable name you changed it to employeeList.
<tr><td>${employee}</td></tr> giving the same error as before
 
Prasad Saya
Rancher
Posts: 506
15
Java Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is only an example. You have to provide your own application's variables (whatever they are).
 
Rohan Kesharwani
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Prasad Saya wrote:That is only an example. You have to provide your own application's variables (whatever they are).




org.apache.jasper.JasperException: /register.jsp (line: [60], column: [35]) quote symbol expected
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:41)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:291)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:97)
org.apache.jasper.compiler.Parser.parseAttribute(Parser.java:238)
org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:169)
org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:160)
org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:1254)
org.apache.jasper.compiler.Parser.parseElements(Parser.java:1473)
org.apache.jasper.compiler.Parser.parse(Parser.java:145)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:244)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:105)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:203)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:374)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:351)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:335)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:595)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:368)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

errors on that line

 
Rohan Kesharwani
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator




and exceptions are

org.apache.jasper.JasperException: /register.jsp (line: [60], column: [2]) According to TLD or attribute directive in tag file, attribute [items] does not accept any expressions
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:41)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:291)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:114)
org.apache.jasper.compiler.Validator$ValidateVisitor.checkXmlAttributes(Validator.java:1242)
org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:880)
org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1545)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2392)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2444)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2450)
org.apache.jasper.compiler.Node$Root.accept(Node.java:471)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2392)
org.apache.jasper.compiler.Validator.validateExDirectives(Validator.java:1854)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:221)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:374)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:351)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:335)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:595)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:368)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
 
Rancher
Posts: 3767
40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the first thing that needs to be said is that you really shouldn't be using a static object like that in a web app.
It's not threadsafe.
Indeed, if another request came in adding a new Employee while the first request was attempting to iterate over the current List, then the first thread would throw a ConcurrentModificationException, and you'd be hard pushed to figure out why.

It's what databases are for.
Though you could make the List threadsafe using Collections.synchronizedList(), though reading that and you'd still have issues with the iterating.
 
Rohan Kesharwani
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Tolls wrote:Well, the first thing that needs to be said is that you really shouldn't be using a static object like that in a web app.
It's not threadsafe.
Indeed, if another request came in adding a new Employee while the first request was attempting to iterate over the current List, then the first thread would throw a ConcurrentModificationException, and you'd be hard pushed to figure out why.

It's what databases are for.
Though you could make the List threadsafe using Collections.synchronizedList(), though reading that and you'd still have issues with the iterating.



I m trying to make this code without database.
That's why I used static so that update in list will have same address
 
Dave Tolls
Rancher
Posts: 3767
40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But you then have the thread-safety issue, and synchronising issues (especially with the JSP side as you can't do that with tags).

If you have to do it this way, then the List must be a synchronized one (as I mentioned above) and then a copy of the list should be provided to the JSP page, via the request.
 
Rohan Kesharwani
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Tolls wrote:But you then have the thread-safety issue, and synchronising issues (especially with the JSP side as you can't do that with tags).

If you have to do it this way, then the List must be a synchronized one (as I mentioned above) and then a copy of the list should be provided to the JSP page, via the request.



i tried still no results any other options..!?
 
Marshal
Posts: 67165
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you redirecting to the JSP rather than forwarding?
 
Rohan Kesharwani
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Why are you redirecting to the JSP rather than forwarding?



it's in else condition.. not a problem.. i will change it right away.. still issue stands
 
Dave Tolls
Rancher
Posts: 3767
40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rohan Kesharwani wrote:
i tried still no results any other options..!?



That wasn't intended to fix this problem.
It was intended to prevent a bug-in-waiting.

Have you added logging so you can check where in the code it is going?

Can you show the current form of the servlet code, along with the logs showing the path through that code it is taking?
Also what values are being stored and passed around?
 
Rohan Kesharwani
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Tolls wrote:

Rohan Kesharwani wrote:
i tried still no results any other options..!?



That wasn't intended to fix this problem.
It was intended to prevent a bug-in-waiting.

Have you added logging so you can check where in the code it is going?

Can you show the current form of the servlet code, along with the logs showing the path through that code it is taking?
Also what values are being stored and passed around?



Employee.java



Register.java



register.jsp



exit.jsp




Type Exception Report

Message /register.jsp (line: [60], column: [20]) quote symbol expected

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

org.apache.jasper.JasperException: /register.jsp (line: [60], column: [20]) quote symbol expected
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:41)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:291)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:97)
org.apache.jasper.compiler.Parser.parseAttribute(Parser.java:238)
org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:169)
org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:160)
org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:1254)
org.apache.jasper.compiler.Parser.parseElements(Parser.java:1473)
org.apache.jasper.compiler.Parser.parse(Parser.java:145)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:244)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:105)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:203)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:374)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:351)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:335)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:595)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:368)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Note:The full stack trace of the root cause is available in the server logs.
 
Dave Tolls
Rancher
Posts: 3767
40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I see no useful logging int here at all.
That section at the end of the doPost is simply never going to happen if there is an error.

Log data as you go, so you at least have a chance of seeing what's happening.

As for the error itself, Prasad gave an example of what the foreach tag should look like.
If there's something about the tag you don't understand then that might be the thing to check on.

Finally, you still have the thread safety issue I mentioned.
 
Rohan Kesharwani
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Tolls wrote:I see no useful logging int here at all.
That section at the end of the doPost is simply never going to happen if there is an error.

Log data as you go, so you at least have a chance of seeing what's happening.

As for the error itself, Prasad gave an example of what the foreach tag should look like.
If there's something about the tag you don't understand then that might be the thing to check on.

Finally, you still have the thread safety issue I mentioned.



Fine. I will try thank you for all the help.

can you just help me in one more thing write a jsp program in which you have a list of class in servlet and you pass that list to jsp to print using forEach
 
Bear Bibeault
Marshal
Posts: 67165
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rohan Kesharwani wrote:can you just help me in one more thing write a jsp program in which you have a list of class in servlet and you pass that list to jsp to print using forEach


That is a very common and straight-forward task:
  • Create the list as one of the standard Java collection implementations of List. (An array will work too, but Lists are easier to deal with.)
  • Add the list to request scope using a well-chosen name.
  • Forward the request to the JSP view.
  • Reference the list in the EL by its name.
  • Iterate over the list using JSTL, for example <c:forEach>
  •  
    Saloon Keeper
    Posts: 2156
    278
    Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator

    Rohan Kesharwani wrote:org.apache.jasper.JasperException: /register.jsp (line: [60], column: [20]) quote symbol expected


    The value for items should be quoted.
     
    Bear Bibeault
    Marshal
    Posts: 67165
    169
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    P.S. The names of scoped variables (those placed into request or other scope) should follow the same naming conventions as Java variable names. So employees, not EMPLOYEES.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!