Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sessions and Servlet not Jsp

 
Sebastian Green
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I mange to handle sessions in my jsp-page but i would like to handle it with servlets instead. Here is my jsp code

Now what dose it take for me to get it going in "servletmode". I dont have J2EE installed but I have servlet-api.jar in my J2SDK. Could anyone help me out, what do I need to type in my jsp and java -file?

Thansk for your time!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What makes you think you need to do anything any different?
 
Siyaa Hoffman
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sebastian,

In your servlet code, in the doGet() or doPost() method, you can get the session from the request object -

request.getSession() would give you the HttpSession. Then you can use the same API session.setAttribute() in the servlet code to set up the session level attribute.
Exactly what you are doing in the JSP.
[ June 01, 2004: Message edited by: Siyaa Hoffman ]
 
Sebastian Green
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well thats the point, Im pretty new to this so Im having problems to communicate from the jsp to the servlet. So i thought a simple sessions example would do the trick. The answer I was looking for was more like: Here is the serlvet code:

package myfirstsession;
public class Site session {......

and here is the jsp code:

<%@ page import="myfirstsession.*" %>

I cant get it to work
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic