• Post Reply Bookmark Topic Watch Topic
  • New Topic

Passing data from jsp to servlet  RSS feed

 
francis varkey
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Respected Sirs,

I have a jsp(reservation.jsp) and an Action class (ReservationAction.java).
I am using struts frame work. In my jsp there is a two dimmensional String array (reservResult[][]) with some values. I have set these string object in request in reservation.jsp.

request.setAttribute("ResSearchResult",reservResult);

While clicking a link in the jsp I have submitting the page to the Action calss. In the action class I am trying to retrieve the request data.

String[][] ReservResult=(String[][])request.getAttribute("ResSearchResult");
but I got null value.
What is the problem. How can solve it.

Thanks
Francis
 
kelby zorgdrager
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when you call request.setAttribute in the JSP it sets data in the *current* request. once the jsp has finished processing, and the results are sent back to the browser, the request (and its attributes) go out of scope. when the end user then invokes an Action by clicking on a link or submitting a form, the server creates a *new* request for that specific interaction.. so, the null that you are receiving is actually correct.

there are other ways to pass data between pages.. some people will use sessions. others will use hidden fields in forms.. it just depends on your strategy and what you are trying to achieve.
 
francis varkey
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For some reason I want to avoid session(related to memory) . Can we pass two dimensional string array values using hidden fields (I think no) ? Can we use
RequestDispatcher Interface and it methods for solving this ?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66158
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by francis varkey:
For some reason I want to avoid session(related to memory

Why? We see this now and again here. The session is a tool for you to use. Used wisely, there should be no issue with utilizing the session.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!