Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

return null instead of session value  RSS feed

 
deep raj
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in a.jsp
i write this code


HttpSession ses1=request.getSession(true);
ses1.setAttribute("name",ss1);


in b.jsp
i write the code
HttpSession ses1=request.getSession(false);
out.print(ses1.getAttribute("name"));


it shows null

what is wrong in this?



and i also want to mention that there is no problem in my browser to save session value

because it run in another web application
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66203
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two things:
  • Please UseCodeTags when posting code to the forums (that's a link, click it).
  • Java code should not be placed in a JSP. I'll assume that this is just for testing and not production code.
  •  
    Thomas Kennedy
    Ranch Hand
    Posts: 137
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Are you sure ss1 exists?
     
    John Jason Reyes
    Greenhorn
    Posts: 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    By default JSP files create HttpSessions, so you don't need to create one.

    You can proceed to this code for a.jsp

    And this code for b.jsp

    The reason why it displays null in your previous code is that session is set to false on b.jsp
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!