• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Life Span of a request.

 
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
If I saved a HttpServletRequest in a session and then tried to do a request.getRequestDispatcher().forward(....) with the request in the session before the session times out. Will I have any problems?
Is there a possibility that the request will be garbage collected by then? If so what are some solutions? Using the HttpServletRequestWrapper?
[ May 23, 2003: Message edited by: Thomas Mcfarrow ]
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The servlet engine manages the request and response objects. You can't save them in a session because the engine might re-use them for efficiency sake.
In any case many of the attached resources, such as the output stream will be totally meaningless after the response has been sent and the client connection closed.
What are you trying to accomplish?
Bill
 
Thomas Mcfarrow
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Scenario:
You have an HTML page with post (original request) and you get a response from a HTML/Servlet/JSP ignoring original request. Next you need to send a request with values from HTML/Servlet/JSP and the original request to a Servlet/jsp.
Why?:
The code was written/designed this way and I didn't have any control of the design. I just need a way to make this work with minimal code change
One fix is building a query string but that is not how a post should work.
So my next thought is to set the Content-Length header field to the size of the query string and put the query string in the header. I believe thats how a post works. Do you know how do to set the query string in the header?
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not clear on something here - are you writing just some sort of client that has to talk to existing servlet/jsp, writing a servlet/jsp that has to respond to a browser request, or what?
Can you establish a session with the data from the first request?
How about writing hidden variables into a form?
(incidently, content length refers to the body of an HTTP message, not headers)
Bill
 
Thomas Mcfarrow
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bill,
I wish I could give you exact details but unfortunately I can't(company policy). So I came up with something very similar.
Lets say any HTML page trys to send a request (via POST) to a servlet but there is an interceptor servlet of sort that works similar to Form Based Authentication or a survey.
(We will pretend the interceptor was survey type servlet)
The way underlying code works is that after the user fills in the required fields in the survey, the results will be submitted to another servlet. This Servlet will respond either back to the survey form (if a field was missed) or with a redirection to the original requested servlet with a query string (from the original HTML request) attached to the url.
This works great for GETS since there are query strings but not for POSTS. One thing I did was build a query string from paramaters when I got a POST. Even though this worked, it is not acceptable since POST don't behave in this manner.
Deep Breath, the bottom line this has to work with any Servlet/HTML/Jsp page that is sending the original POSTS request. I am not customizing those files. I am concerned with the interceptor layer.
I can't change the original design of the code. I just need to find a way to get POSTS working like they should.
---------------------------
Yes a session is established.
Yes I realize the content-length (my mistake) involves the body of the HTTP Message. Is there a way to set the body of the Http Request Message with the query string? Or how do you build a request programatically?
[ May 24, 2003: Message edited by: Thomas Mcfarrow ]
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Post sends name-value data pairs in the body of the HTTP message.
The best way to understand what goes on with a Post is to intercept the conversation between a browser and server so you can look at the actual headers and body created when a Form is Posted. When I was writing a book on SOAP I wrote a utility to do this, and there are also other utilities for the same purpose.
You can download
my UtilSnoop program (in Java) - its at the bottom of the page.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic