wood burning stoves 2.0*
The moose likes Servlets and the fly likes problem with sessions - urgent please Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "problem with sessions - urgent please " Watch "problem with sessions - urgent please " New topic
Author

problem with sessions - urgent please

Vishnu Murthy
Ranch Hand

Joined: Jan 04, 2001
Posts: 56
Hi all,
i am working on tomcat webserver, i am created new session in servelt using HttpSessions and putting some values in the session and when i try to access these session value in JSP page it is giving the value as null i don't know why.
my servlet code is like...
.
.
HttpSession session = req.getSession(true);
String dsn= getInitParameter();
session.putValue("dsn",dsn);
.
.
when i try to access the session in my JSP page as
.
.
String sesvalue = (String)session.getValue("dsn");
out.println(" session value "+sesvalue);
.
.
it is displays the null value
can any one help as how to solve this problem.
thank in advance
Dmitriy Pavlyuk
Ranch Hand

Joined: Mar 25, 2001
Posts: 33
Hi
Try to send jsessionid with request as follow
<a href="main.jsp;jsessionid=<%=session.getId()%>">Page</a>
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
Your servlet and the JSP have to be in the same web application if they are to share the same session. Perhaps that is the cause of the problem.
Bill
DAYANAND BURAMSHETTY
Ranch Hand

Joined: Aug 06, 2001
Posts: 34
//servlet
public void service(HttpServletRequest req, HttpServletResponse res)throws IOException,ServletException
{
Session session=req.getSession();
String userid="Dayanand";
Xyz obj1=new Xyz();
session.setAttribute("OBJECT1",obj1);
session.setAttribute("USERID",userid);
...
}
//jsp
<%
Xyz obj= (Xyz)session.getValue("OBJECT1");
String userid=(String)session.getAttribute("USERID");

%>


Dil se....,<BR>Dayanand<BR>0065-8839071(off)<BR>0065-7547034(Res0
Raghavendra Holla
Ranch Hand

Joined: Jun 02, 2000
Posts: 58
getValue and putValue are deprecated !. They will return null value from Version 2.2. So as Dayanad indicates use getAttribute and setAttribute. For further clarification refer Servlet API documentation.
regards
holla.
DAYANAND BURAMSHETTY
Ranch Hand

Joined: Aug 06, 2001
Posts: 34
Originally posted by DAYANAND BURAMSHETTY:
//servlet
public void service(HttpServletRequest req, HttpServletResponse res)throws IOException,ServletException
{
Session session=req.getSession();
String userid="Dayanand";
Xyz obj1=new Xyz();
session.setAttribute("OBJECT1",obj1);
session.setAttribute("USERID",userid);
...
}
//jsp
<%
Xyz obj= (Xyz)session.getAttribute("OBJECT1");
String userid=(String)session.getAttribute("USERID");

%>

Vishnu Murthy
Ranch Hand

Joined: Jan 04, 2001
Posts: 56
Hi Dayanand
i am using jdk1.2.2 so when i try to use the method
session.setAttribute("string",object);
it is not compiling and giving the error
setAttributes(java.lang.String, java.lang.Object) not found in interface javax.servelt.http.HttpServlet.
so do u want me to change jdk version?
and also can u please tell me how to set initial parameters for web.xml file on tomcat webserver.
thankq
vishnu
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem with sessions - urgent please
 
Similar Threads
How to use session Tracking in JSP
Unable To connect to Database !!
Struts 2 -Eclipse
Database Problem
getting session value in JSP