• Post Reply Bookmark Topic Watch Topic
  • New Topic

help needed in request.getParameter

 
t thivya
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to pass a object of a class from one jsp page to another jsp page?

I had set the object of one class to one variable. In Screen3.jsp i have given like
<A HREF = 'http://localhost:8080/JSP/Screen4.jsp? valueobject=<%=v1%>'> <%=s%> </A>
where v1 is the object of an class.

In Screen4.jsp, i am retrieving the variable like
v2=(ValueObject)request.getParameter("valueobject");

But i am unable to do it. Help me plz. Thanks in Advance.
 
Scott Selikoff
author
Bartender
Posts: 4033
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a session object.



You should probably check for nulls when retrieving the object, and it must be explicitly cast a class if you want to use any class methods on it other than those defined in Object.


Alternatively, you can save objects in cookies or pass them via URL parameters as in your example, but technically those can't be passed as objects. They must be converted to encoded/decoded in some string format. Session objects are used, therefore, to save complex objects not easily encoded as string parameters or to monitor state.
 
t thivya
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have a doubt in the reply. In one JSP page can i set the object to a session and in another JSP page can i access the object?
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First you cannot send objects as query string as you had did in your first post.

Use attributes to set objects. Based on your requirement use any one of the available scopes (context/session/request/page).

You can set a session attribute in one jsp page and retrieve the same in any other page in the same context as long as it is part of the same user session.
 
t thivya
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
Thanks for u r reply. I have got it. I used sessions and i set the object using setAttribute and got the object in another JSP page. Thanks a lot.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!