FW: String added to session in servlet not available in jsp
I really sorry the last message I sent it by mistake, is difficult to me write code in outlook ;) well Try this HttpSession session = request.getSession(true); String username = request.getParameter(username) if ( username == null ) username = noParameter; if ( .equals( username ) ) username = noParameter; session.setAttribute(usr, username); I'm thinking that your request parameter is empty.. Try this and tell us Sincerely Lic. Computer Science Erlis Vidal Santos -Original Message- From: DA-Erlis Vidal Sent: Thursday, October 09, 2003 11:02 AM To: 'Tomcat Users List' Subject: RE: String added to session in servlet not available in jsp And how you get the session in your JSP?? Try this HttpSession session = request.getSession(true); String username = ( request.getParameter(username) != null ? request.getParameter(username) : ) ; session.setAttribute(usr, username); Sincerely Lic. Computer Science Erlis Vidal Santos -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, October 09, 2003 10:54 AM To: Tomcat Users List Subject: RE: String added to session in servlet not available in jsp Can you please show how are you creating the session object??? No worries, here it is: HttpSession session = request.getSession(true); session.setAttribute(usr, request.getParameter(username)); Sincerely Lic. Computer Science Erlis Vidal Santos -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, October 09, 2003 10:44 AM To: [EMAIL PROTECTED] Subject: String added to session in servlet not available in jsp Hi, I created a session object and added a string (username) to it. Systemout.println shows the username from the request. My page is then forwarded to another as follows: RequestDispatcher disp = ctx.getRequestDispatcher(target); disp.forward(request, response); On this jsp page, I have teh following code: String usr = (String)session.getAttribute(usr); out.println(User: + usr + !); out.println(Session Id: + session.getId()); The page displays the session Id but not the usr. I'm quite baffled at why this is the case. looking in google for similar problems, but any help would be much appreciated! Rudi - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: FW: String added to session in servlet not available in jsp
No worries. I added the following to doPost in my servlet: HttpSession session = request.getSession(true); String username = request.getParameter(username); if ( username == null ) username = noParameter; if ( .equals( username ) ) username = noParameter; System.out.println(username); session.setAttribute(usr, username); I added the following to my JSP: String username = ( request.getParameter(usr)); out.println(username + username); String usr = (String)session.getAttribute(usr); out.println(usr + usr); I should added that my JSP is a frameset with 2 frames. That could be the problem!!! Rudi I really sorry the last message I sent it by mistake, is difficult to me write code in outlook ;) well Try this HttpSession session = request.getSession(true); String username = request.getParameter(username) if ( username == null ) username = noParameter; if ( .equals( username ) ) username = noParameter; session.setAttribute(usr, username); I'm thinking that your request parameter is empty.. Try this and tell us Sincerely Lic. Computer Science Erlis Vidal Santos -Original Message- From: DA-Erlis Vidal Sent: Thursday, October 09, 2003 11:02 AM To: 'Tomcat Users List' Subject: RE: String added to session in servlet not available in jsp And how you get the session in your JSP?? Try this HttpSession session = request.getSession(true); String username = ( request.getParameter(username) != null ? request.getParameter(username) : ) ; session.setAttribute(usr, username); Sincerely Lic. Computer Science Erlis Vidal Santos -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, October 09, 2003 10:54 AM To: Tomcat Users List Subject: RE: String added to session in servlet not available in jsp Can you please show how are you creating the session object??? No worries, here it is: HttpSession session = request.getSession(true); session.setAttribute(usr, request.getParameter(username)); Sincerely Lic. Computer Science Erlis Vidal Santos -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, October 09, 2003 10:44 AM To: [EMAIL PROTECTED] Subject: String added to session in servlet not available in jsp Hi, I created a session object and added a string (username) to it. Systemout.println shows the username from the request. My page is then forwarded to another as follows: RequestDispatcher disp = ctx.getRequestDispatcher(target); disp.forward(request, response); On this jsp page, I have teh following code: String usr = (String)session.getAttribute(usr); out.println(User: + usr + !); out.println(Session Id: + session.getId()); The page displays the session Id but not the usr. I'm quite baffled at why this is the case. looking in google for similar problems, but any help would be much appreciated! Rudi - To unsubscribe, e-mail: tomcat-use [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: FW: String added to session in servlet not available in jsp
Frames with sessions can be a complicated beast if cookies are disabled: - First make shure that you encode all frame url's in the top level framset. Otherwise each frame will get his own session. - After that make shure that all frames keep in sync with the session id. The simple design with one navigation frame and one or more content frames which contain own links will not work as intended if you are not prepared to deal with the session invalidation. See what happens with two frames where each frame contains one URL encoded link: - Start - two frames that belong to the same session are created. - Wait long enough to time out the session. - Klick on a link in one of the frames. - tomcat creates a new session, the link in this frame will contain the new session id, the other frame still contains the old session id. - Klick on the link in the other frame. - Bingo ! tomcat creates a new session, and now both frames are bound to different sessions. To avoid this problem there are some solutions: - Avoid frames - Just use links in one frame - Update the other frames (that requires some javascript) - Set a refresh in all frames, that is just short enough to stop the session from invalidating. (This will give you some unhappy users) -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, October 09, 2003 5:30 PM To: Tomcat Users List Subject: Re: FW: String added to session in servlet not available in jsp I should added that my JSP is a frameset with 2 frames. That could be the problem!!! - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]