• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

passing parameter from jsp to servlet

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,
i want to pass ArrayList from jsp page to servlet.I am not able to pass this variable through request.how can i pass that one . if i am setting it inoto session it is accessible in servlet but i don't want to put much data in session.
it is very urgent.
can any one suggest me any solution for this problem
Thanks in advance
PunPun
 
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I am not able to pass this variable through request



Why aren't you able to use request attributes? Are you using Redirect mechanism?
[ April 03, 2006: Message edited by: Vishnu Prakash ]
 
Pun Pun Mishra
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no i am setting like this
request.setAttribute("result",recordList);
recordList is my ArrayList.but this recordList i am not able to get in the servlet by using request.getAttribute("result");null value i am getting.
what should i do to pass this varibale from jsp to servlet b'coz from servlet to jsp it is possible but vice varsa is not happening
punpun
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
use RequestDispatcher pass request to next page .

RequestDispatcher rd = request.getRequestDispatcher("***.jsp");
rd.forward(request, response);
 
author
Posts: 288
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to understand the HTTP paradigm first. You can set a request attribute in a servlet and then can use it in a JSP, but you cannot do it from JSP to Servlet, because the first request goes out of scope and the servlet will be receiving a new request.

The JSPs were created to get rid of the unsightly and unmaintainable out.println("<html>..</html>"). Your browser can understand only HTML. So when you make a request no-1 from the browser, your request parameters are passed to your servlet in the web container. The servlet, controls the flow and does some stuff and finally forwards the request to your JSP. The JSP engine converts the JSP to a servlet with all the out.println(<html></html> statements. finally output html sent back to the client from the _jsp_converted servlet and your request no 1 is complete (request/response). Any attributes you have set in the JSP have gone out of scope now. When the request no 2 invoked the same process repeats. If you set it in a session scope then it will be available until the session is invalidated.

Hope it explains it.
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You either put it in the session, or rewrite your JSP page.
There may be some problem with your logic.
Why passing an array from JSP, which is a view, to a servlet ?
The servlet should use the data posted by the view.
Correcting this problem first may solve the whole thing.
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


but you cannot do it from JSP to Servlet,



It is possible, provided your JSP Page doesn't do anything(doesn't output anything to the client) else other than just forwarding the request to the destination servlet using RequestDispatcher.

But forwarding from a jsp to servlet is NOT considered best practice as JSP is meant for presentation and NOT for application processing.
 
If you believe you can tell me what to think, I believe I can tell you where to go. Go read this tiny ad!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic