Forums Register Login

Can I use Servlet Session in JSP Page.

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
Then YOU must do the pig's work! Read this tiny ad. READ IT!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1722 times.
Similar Threads
showDocument doesn't work on IE
session value from jsp -> Servlet / Servlet -> jsp
session problem in tomcat 5.5
Session question
post to servlet
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 19, 2024 01:02:15.