This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes response body Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "response body" Watch "response body" New topic
Author

response body

Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

i have this specification:
This is the plain text response part of the POST originated by the Server in the step above. Encoding must be as Name=Value fields
separated by carriage-return-linefeeds (CRLF).
status=xx
RedirectURL=xxx
StatusDetails=xxx

IMPORTANT NOTE: Before writing the three fields above to the Response object of the POST, please ensure you clear your response
buffer to remove any header code, comments or HTML. The Sage Pay Server is expecting “Status=” to be the first characters in the
response.

I am not sure what this means:
this is my attempt but i am getting an invalid state exception



the exception


but the response works, so what am i supposed to be doing?
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4338
    
    7

It might be useful to see what line of your code the exception is being thrown by (it'll be later in that stack trace), but I'd guess it's line 9 of that snippet.

I think the problem is the sendRedirect() call. That tries to set and send the headers of the response, and will throw an exception if the response is already committed. And writing to and/or flushing the output stream will commit the response (i.e. start sending content to the client).

Why are you trying to redirect? I'd expect your servlet to want to return content or redirect the client, but not both.
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

yes it was line 9, my redirect.
umm i am doing the redirect because that is what i always do, so i don't need that line at all...
(will read the chapter about buffers again tonight)
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

(And it wouldn't make any sense to redirect to the string "url" anyway.)

If you're supposed to be sending back a plain text response, redirecting wouldn't make any sense: my guess is something is expecting to get the response and do its own redirection.
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

the second line is the url to redirect the user to in our system.
Thanks both of you, just removing the redirect gets rid of the exception. can i just double check what is happening flow wise here

Sorry if this is a bit rambling but i am trying to understand...

the 3rd party are calling my servlet with the usual request and response.
I am updating the response
The 3rd party are reading the response (no idea how they are doing that, same way as the client wondow i suppose)
as we can't do a redirect now (the response has been played with) what are the 3rd party doing with the url i give them, starting a new post, like the user clicking a link?

yours thankfully
Wendy
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

More or less. They could be sending it to the client, it could be used directly by a client and used via JavaScript, it could be presented as a link, and so on.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: response body
 
Similar Threads
Japanese Charachter not Working in JSP in WAS 4.0.3
Can a servlet architecture download a file?
IllegalStateException problem
Upload Excel using IO and servlet
Post parameters are becoming null (at random)