• 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

Sessions JSP,JavaBeans and Servlets,

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can I include sessions in JSP, Java Beans and Servlets?
I am using JSP model 2 architecture to seperate business logic from presentation.
using MVC (Model(java bean) View(jsp) Control(servlet))
 
Ranch Hand
Posts: 977
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
At jsp:
<%@ page session="true"%>
or if you don�t want to create one
<%@ page session="false"%>
note that the true value is the default and if you wanna use a session in your jsp you don�t have do do nothing
at servlets:
HttpSession s = request.getSession(true);
this command creates a new session if one already is not created and if so just recovers the session.

HttpSession s = request.getSession(false);
this command recovers a session already created but if one doesn�t exist don�t create one.

and you can use:
setAttribute(String name, Object value);
to bind your javabeans to the session
and then recover them with:
getAttribute(String name);
and don�t forget to cast it back to it�s type.
 
reply
    Bookmark Topic Watch Topic
  • New Topic