Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Cant get value from session

843836Jan 3 2005 — edited Jan 4 2005
My servlet doesnt get session value "user" its always null
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException {
		
		HttpSession session = request.getSession(true);
 		String user = (String)session.getAttribute("user");
		System.out.println("Session check"+user);	
                                            
//For some reason the user is always null..... In the previous jsp page when I say String user = (String)session.getAttribute("user"); if(user == null) { response.sendRedirect("index.jsp"); -- This works and it gets the user... 
		
		if(user == null) {
		RequestDispatcher rd = null; 
		rd = getServletConfig().getServletContext().getRequestDispatcher("/index.jsp");
		if (rd!=null)
		rd.forward(request,response);
		}
I havent changed the value of user at all... In previous JSP it accepts the user in session and gets the value.... in the servlet its not.. any ideas? The jsp page uses POST method and this servlet is called using that.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 1 2005
Added on Jan 3 2005
28 comments
511 views