59908F11DF53149C9DAD6A244CAC2EC7hello
welcome existing usernull
OCPJP 6, OCEWCD Java EE 6
nithin chinni wrote:Sorry found the solution. It seems JPS have some kind of useless stuff............ So i was having that problem. By using this statement I could figure out my problem
<%@ page session="false" %>
Meri Zindagi Hain Tab Tak.. Jab Tak Tera Sahara.... Har Taraf Tu Hi Tu Hain SAI Tera Hi Hain Nazara.....
Yogendra Joshi wrote:HttpServletRequest.getSession() - This method returns a new session irrespective of whether one already exists...
Prasad Krishnegowda wrote:
Yogendra Joshi wrote:HttpServletRequest.getSession() - This method returns a new session irrespective of whether one already exists...
No..
request.getSession(), will check for the existing one, if session exists it returns it.. if no current session only, it will create a new session..
Meri Zindagi Hain Tab Tak.. Jab Tak Tera Sahara.... Har Taraf Tu Hi Tu Hain SAI Tera Hi Hain Nazara.....
Yogendra Joshi wrote:
Prasad Krishnegowda wrote:
Hey Prasad,
Thanks for correcting me. I just looked the API and its exactly what you are saying.
Learning Day Today!![]()
Yogendra
Yogendra Joshi wrote:
nithin chinni wrote:Sorry found the solution. It seems JPS have some kind of useless stuff............ So i was having that problem. By using this statement I could figure out my problem
<%@ page session="false" %>
Hey Nithin,
JSP's does not have useless stuff. Its just that your knowledge on jsp and servlet API is too weak If you look up the HttpServletRequest API you will notice there are two methods for getting the session:
HttpServletRequest.getSession() - This method returns a new session irrespective of whether one already exists...
HttpServletRequest.getSession(boolean) - If you pass false in here, It will always look for an existing session, if it doesnt find one, It will return null, if you pass true, it will check if there is an existing session, if it doesnt find one, It will create new one.
So in your code, when you wanted to check for the existing session, you should have done request.getSession(false), It would have given you an existing session.
Once you get hold of the session, you can set the attribute using HttpSession.setAttribute methods and use that attribute on every page where you need to display the userName.
I Hope I have been clear in making you understand your issue.
Thanks,
Yogendra.
Thanks and Regards
Souvik
SCJP, SCWCD, OCEJWSD
nithin chinni wrote:So if I set in JSP that session="false" the session that I create when someone hit login page it will be a new session and thats just what I need
Souvik Dasgupta wrote:
Hi Nitin,
Could you please set
inside the DemoServlet and retry?
The existing session will be used in this case, and new session will not be created.When you write , you create a new session and it does not have username set into it.
Thanks and Regards
Souvik
Prasad Krishnegowda wrote:
nithin chinni wrote:So if I set in JSP that session="false" the session that I create when someone hit login page it will be a new session and thats just what I need
Setting session=false, just tells that the inbuilt jsp variable session is not available to this page. It doesn't mean that no session will be created..
Bear Bibeault wrote:Bad solution. You should not be trying to control when sessions are created and destroyed, You do not need to have a new session for a login. Simply control what's placed into the session rather than trying to control the session itself.
OCPJP 6, OCEWCD Java EE 6
Bear Bibeault wrote:You should check whether there object(s) you place in the session are there or not. If not there, you will receive a null.
OCPJP 6, OCEWCD Java EE 6
That new kid is a freak. Show him this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|