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

Sending a list from Servlet to JSP  RSS feed

 
Ruchika Ch
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am trying to display a list fetched from DB in a JSP.
My servlet mapping is:


The code in the servlet is:


The code in JSP is:

The request is not coming back to the JSP page.
If i change the servlet and have "request.getRequestDispatcher("/pages/ViewCompletedWWDocs.jsp").forward(request, response);" un commented, I get exception "java.lang.IllegalStateException: Cannot forward a response that is already committed". Please advise.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66205
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A few things:
  • You should be using request scope and a forward, not a redirect and the session. If you are having problerms with the forward, fix that rather than simply trying something else that's unsuitable.
  • You should be using the JSTL and EL in the JSP, not obsolete and dicredited Java scriptlets.
  • If you do use the session for a value (and in this case, it does not seem appropriate), then you must look in the session for it. You cannot put something in session scope and then expect to find it in request scope.
  •  
    Dave Tolls
    Rancher
    Posts: 2914
    36
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Ruchika Ch wrote:If i change the servlet and have "request.getRequestDispatcher("/pages/ViewCompletedWWDocs.jsp").forward(request, response);" un commented, I get exception "java.lang.IllegalStateException: Cannot forward a response that is already committed". Please advise.


    When uncommented do you still have the redirect?

    Could you show the code giving this exception, not with commented out bits, just so we can see exactly what code is causing the problem? As Bear says, you should be forwarding so if there's a problem with that then that's what needs to be fixed.
     
    Navin Manwatkar
    Greenhorn
    Posts: 10
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    As Bear mentioned in point #3, you are setting the value in session and looking up in request. Either you change session.setAttribute("completedDocs", docs); to request.setAttribute("completedDocs", docs); or to the opposite way.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!