Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Using getOutputStream with a servlet redirect? (http://www.velocityreviews.com/forums/t135020-using-getoutputstream-with-a-servlet-redirect.html)

DiscoStu 07-08-2004 06:55 PM

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

John C. Bollinger 07-08-2004 10:47 PM

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

Java Architect 07-08-2004 11:00 PM

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




Sudsy 07-08-2004 11:17 PM

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!


DiscoStu 07-09-2004 06:32 AM

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.

John C. Bollinger 07-09-2004 01:58 PM

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

DiscoStu 07-09-2004 06:16 PM

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.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57