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

How to pass values from servlet to jsp

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
How do we pass values from servlet to jsp?
Thanks
--Lakshmi

[ May 20, 2004: Message edited by: Lakshmi siri ]
[ May 20, 2004: Message edited by: Lakshmi siri ]
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want people to take the time to answer your questions, how about spending a few seconds of your own time to come up with meaningful topic titles? "Help me" doesn't tell anyone what your question is about; be they people who can answer the question for you, or people who might be looking for the same answer.

Hint: you can edit your original post to change the topic title.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lakshmi,
You can put the values in the request using request.setAttribute().
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Besides request, you can also use session.
In the JSP you can define the scope of a java bean. This scope may be "page" (default value), "request", "session", "application".
I always use request and session.
What's the difference between request and session ?
A request can be compared with going to a bar, asking for a beer and paying it when you get it. The bartender doesn't have to keep in mind that you have to pay.
A session is going to a restaurant and eating � la carte. You demand a salad for starters, a main dish, a dessert and a coffee. And after that, you pay. The session starts with you demanding the salad and ends with you paying the bill.

SO you have a choice. If you can forget about the values as soon as you've showed the values of the java bean on a HTML page, use request. If you want to keep in mind what the user did during his visit on your web site, use session.

When using request, you should write
request.setAttribute("mybean", mybean)
And in the JSP you have
<jsp:useBean id="mybean" class="org.gertcuppens.general.MyBean" scope="request"/>

when using session you should write
HttpSession session = request.getSession(true); // if you didn't have a session in the request
or
HttpSession session = request.getSession(false) ; // if you already have put a session in the request and merely wants to add something to it

session.setAttribute("myBean", myBean);

And the JSP can read this value by
<jsp:useBean id="myBean" class="org.gertcuppens.general.MyBean" scope="session"/>
 
My favorite is a chocolate cupcake with white frosting and tiny ad sprinkles.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic