Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

help needed in request.getParameter

 
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.
 
author
Posts: 4223
33
jQuery Eclipse IDE Java
  • 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?
 
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.
    Bookmark Topic Watch Topic
  • New Topic