• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problem with sessions - urgent please

 
Vishnu Murthy
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13071
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
//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");

%>
 
Raghavendra Holla
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic