File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Can I use Servlet Session in JSP Page. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Can I use Servlet Session in JSP Page." Watch "Can I use Servlet Session in JSP Page." New topic
Author

Can I use Servlet Session in JSP Page.

pras patel
Greenhorn

Joined: Oct 28, 2000
Posts: 4
I wanted to know wheater a session obj created in servlet can be used in a jsp. I want some parameter to be passed , i have use
sendRedirect() and also forward of the requestdispatcher.
saradhi pantra
Greenhorn

Joined: Dec 03, 2000
Posts: 2
hai patel,
u can use the servlet session object in jsp page.
u use RequestDispatcher .In this u use forward() method
It redirct the request to that JSP page .In that JSP page
u call session.getValue()
saradhi
Kiran Kumar
Ranch Hand

Joined: May 18, 2001
Posts: 107
hi all
i am having the same problem. i am setting some attributes for a session object in my servlet and using RequestDispatcher.forward to a new jsp. i am not able to get the attribute values in my jsp. . when i say session.getAttribute(****) i am getting null, somebody please help me in this.

Thanks<br /> <br />Kiran <br /> <br />SCEA, SCJP 1.4,<br /> <br />"First they ignore u, then they laugh at u, then they fight u, <br />then u will win<br /> <br />Mahatma Gandhi"
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

In your servlet, you must use the passed in request object to obtain 'the' session, not just any session. This might be the problem if you're not doing it.

Session ses = request.getSession();
ses.setAttribute("hello", "hello");
.
.
.
Then you get the RequestDispatcher and forward
RequestDispatcher rd = getRequestDispatcher("/somePage.jsp");
rd.forward(request, response);
.
.
inside somePage.jsp, you should be able to access "hello" like you already know how to do.
Kiran Kumar
Ranch Hand

Joined: May 18, 2001
Posts: 107
i called ServletContext.getRequestDispatcher(**). but if i give the whole absolute path of the jsp page it is returning null.
like
RequestDispatcher rd = ServletContext.getRequestDispatcher("http://localhost:7001/checkmail.jsp")
here rd will be null. but if i give relative path like "/checkmail.jsp" i will get the rd object but when i call rd.forward(**,**) the jsp page is not coming
i used the HttpServletRequest.getRequestDispatcher() also.
i am using Weblogic 6.0 application server.
i cannot give relative path like "/checkmail.jsp" becoz the control will be returned from a servlet ie "http://localhost:7001/examplesWebApp/MainServlet" and it is taking "http://localhost:7001/examplesWebApp/checkmail.jsp" so i am not able to view the jsp page.
the MainServlet is a FrontController for the application and all the html/jsp request will go through this servlet. so according to the data got from the backend i should send the objects to the jsp page as session attributes.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can I use Servlet Session in JSP Page.
 
Similar Threads
Session question
showDocument doesn't work on IE
session value from jsp -> Servlet / Servlet -> jsp
post to servlet
session problem in tomcat 5.5