This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes JSP and the fly likes passing parameters from servlet to jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "passing parameters from servlet to jsp" Watch "passing parameters from servlet to jsp" New topic
Author

passing parameters from servlet to jsp

ramanuja varun
Ranch Hand

Joined: Aug 31, 2007
Posts: 47
can we pass parameters from servlet to jsp without using attributes
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

Why? Scoped variables (what you called attributes) are the correct means to carry data from a servlet to a forwarded JSP.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
ramanuja varun
Ranch Hand

Joined: Aug 31, 2007
Posts: 47
i just wanted to know if there is a way to pass parameters from servlet to jsp without using the attributes.Please let me know if the answer is yes and do explain with an example
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

When you say "parameters" are you talking specifically about request parameters (as submitted by a form) or using the term generically to mean "data"?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

Originally posted by ramanuja varun:
... without using the attributes.
It's also a good idea to use correct terminology. The correct term is "scoped variables", not "attributes".
ramanuja varun
Ranch Hand

Joined: Aug 31, 2007
Posts: 47
Yes sir, i am talking about request parameters.Is there a way?
[ September 16, 2008: Message edited by: ramanuja varun ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

Request parameters will automatically be carried along on the request and you don't have to do a single thing.

That assumes, of course, that you are forwarding the request from the servlet to the JSP. If you are performing a redirect, a new request is generated and the parameters will be lost.

Customarily, if these data values need to be kept around, scoped variables in session scope are used.

But other ways could be to store them in cookies, write them to a database, write them to files, and so on.

What's your beef with scoped variables?
[ September 16, 2008: Message edited by: Bear Bibeault ]
ramanuja varun
Ranch Hand

Joined: Aug 31, 2007
Posts: 47
sir Imagine i have a form where in i enter the username and password.Now i have passed them on to the servlet.Further I would like to know is there a way to pass the same request parameters from the servlet to another jsp without using set and getAttributes.I hope the scenario is clear now.
Thanks
[ September 16, 2008: Message edited by: ramanuja varun ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60050
    
  65

Just like I said. It depends how you are traversing from the servlet to the JSP.
ramanuja varun
Ranch Hand

Joined: Aug 31, 2007
Posts: 47
sir can you please explain with a n example how to use the cookies or session to perform the task
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: passing parameters from servlet to jsp
 
Similar Threads
Passing parameters from Servlet to JSP
how to add values to servlet and call that servlet
one servlet to another servlat
Passing data from servlet/jsp
getParameters names from jsp?