![]() |
Using getOutputStream with a servlet redirect?
Hello,
I want to pass information from my servlet into one of my JSP pages but the Session object doesen't seem to be working for my application. I was wondering, can I get the output stream of my HttpServletResponse object and attach some data to it before I call sendRedirect("NewPage.jsp"); I want NewPage.jsp to getInputStream on its HttpServletRequest object and retrieve the information the servlet attached. Is this feisable? I would normally just put the object in my HttpSession but it keeps getting reset because I have to web-servers talking to each other and not a web-server and a browser. Thanks |
Re: Using getOutputStream with a servlet redirect?
DiscoStu wrote:
> Hello, > > I want to pass information from my servlet into one of my JSP > pages but the Session object doesen't seem to be working for my > application. I was wondering, can I get the output stream of my > HttpServletResponse object and attach some data to it before I call > sendRedirect("NewPage.jsp"); No. That is to say, you can write data to the output stream, and as long as you're buffering and the data are not enough to cause the buffer to be flushed then you'll be able to send the redirect. HOWEVER, whatever you have written to that output stream will have dropped into a black hole by the time the new request arrives. > I want NewPage.jsp to getInputStream on its HttpServletRequest object > and retrieve the information the servlet attached. Is this feisable? I No. See above. > would normally just put the object in my HttpSession but it keeps > getting reset because I have to web-servers talking to each other and > not a web-server and a browser. You are getting a new session for each request because the requests do not contain the session cookie or any other form of session ID. You might be able to fix it by enabling and using URL rewriting to pass the session ID around. John Bollinger jobollin@indiana.edu |
Re: Using getOutputStream with a servlet redirect?
To the OP:
Rather than trying a workaround, why not figure out what's wrong with your session handling. Also, if you are trying to get info to the JSP, you should use the request object instead of the session. Hope this helps "John C. Bollinger" <jobollin@indiana.edu> wrote in message news:cckitl$b95$1@hood.uits.indiana.edu... > DiscoStu wrote: > > > Hello, > > > > I want to pass information from my servlet into one of my JSP > > pages but the Session object doesen't seem to be working for my > > application. I was wondering, can I get the output stream of my > > HttpServletResponse object and attach some data to it before I call > > sendRedirect("NewPage.jsp"); > > No. That is to say, you can write data to the output stream, and as > long as you're buffering and the data are not enough to cause the buffer > to be flushed then you'll be able to send the redirect. HOWEVER, > whatever you have written to that output stream will have dropped into a > black hole by the time the new request arrives. > > > I want NewPage.jsp to getInputStream on its HttpServletRequest object > > and retrieve the information the servlet attached. Is this feisable? I > > No. See above. > > > would normally just put the object in my HttpSession but it keeps > > getting reset because I have to web-servers talking to each other and > > not a web-server and a browser. > > You are getting a new session for each request because the requests do > not contain the session cookie or any other form of session ID. You > might be able to fix it by enabling and using URL rewriting to pass the > session ID around. > > > John Bollinger > jobollin@indiana.edu |
Re: Using getOutputStream with a servlet redirect?
>> would normally just put the object in my HttpSession but it keeps
>> getting reset because I have to web-servers talking to each other and >> not a web-server and a browser. > > > You are getting a new session for each request because the requests do > not contain the session cookie or any other form of session ID. You > might be able to fix it by enabling and using URL rewriting to pass the > session ID around. John, I resisted replying earlier. What I believe the OP needs to do is map out, on paper or a white board, precisely how the protocol works. If one doesn't understand cookies and URL-rewriting as a mechanism to maintain session state then obviously they won't be able to arrive at a suitable architecture. Only once you comprehend the nature of the underlying protocol, and particularly the roles of client and server, can you map your requirements appropriately. If you search the list archives you'll rapidly locate a jakarta package which can emulate a browser in application-to-application scenarios. Trying to use examples as boilerplate in place of actual empirical testing won't save you time in the longer term. Translation: It's doable, but you're going to have to do a bit of digging into the documentation and get your hands dirty. 'Tis always the best way! |
Re: Using getOutputStream with a servlet redirect?
> Translation:
> It's doable, but you're going to have to do a bit of digging into > the documentation and get your hands dirty. > 'Tis always the best way! More simply: RTFM. |
Re: Using getOutputStream with a servlet redirect?
Sudsy wrote:
> I resisted replying earlier. What I believe the OP needs to do is > map out, on paper or a white board, precisely how the protocol works. > If one doesn't understand cookies and URL-rewriting as a mechanism > to maintain session state then obviously they won't be able to > arrive at a suitable architecture. Yes, you're quite right. Perhaps I should have resisted a little harder myself. > Only once you comprehend the nature of the underlying protocol, > and particularly the roles of client and server, can you map your > requirements appropriately. I can't argue with that. John Bollinger jobollin@indiana.edu |
Re: Using getOutputStream with a servlet redirect?
> Translation:
> It's doable, but you're going to have to do a bit of digging into > the documentation and get your hands dirty. > 'Tis always the best way! So I took your advice and looks carefully through the servlet spec. I never knew the Request object had get/setAttribute() methods, I only thought it had get/setParameter() methods which take strings. I needed objects however. That worked out well, but left me stumped on how to pass the Request object with the attributes in it to my SearchResults.jsp page. Until I found the RequestDispatcher class, thats a handy little class but it seems oddly packaged, along with SingleThreadModel. Both are tiny classes just kind of hanging out there. Thanks everyone |
| All times are GMT. The time now is 09:22 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.