• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Sending a list from Servlet to JSP

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
  •  
    Rancher
    Posts: 4801
    50
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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.
     
    Greenhorn
    Posts: 10
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • 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.
     
    Barry's not gonna like this. Barry's not gonna like this one bit. What is Barry's deal with tiny ads?
    a bit of art, as a gift, the permaculture playing cards
    https://gardener-gift.com
    reply
      Bookmark Topic Watch Topic
    • New Topic