Forums Register Login

response.Status codes

+Pie Number of slices to send: Send
Hello everyone,

Are response.Status codes included in the exam?

( for example response.SC_ACCEPTED etc)
+Pie Number of slices to send: Send
It is better for you to know some common codes, like 200, 404 and 500. However, the exam wont ask you what is the meaning of code 200.

Nick
+Pie Number of slices to send: Send
Thanks.

How about in real world.

For example, if in the code someone use the following:

response.SC_REQUEST_TIMEOUT;

1- does it invalidate the session?
2- is anyone actually sets these codes in real world?

-Lida
+Pie Number of slices to send: Send
 


For example, if in the code someone use the following:

response.SC_REQUEST_TIMEOUT;

1- does it invalidate the session?


Setting the status code does not affect the session, you need to manually invalidate the session, or it has been already invalidated. The error code is just be used to tell the browser or user the problem encountered.


2- is anyone actually sets these codes in real world?


If you wanna use the default error page by the browser, you need to set it. If you have customerized error messages, you might no need it.

Nick
+Pie Number of slices to send: Send
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {

String newurl = "http://www.newurl.com";
response.setContentType("text/html");
response.setStatus(301);
//HttpServletResponse.SC_MOVED_PERMANENTLY == 301
response.setHeader("Location", newurl);
+Pie Number of slices to send: Send
Thanks, it makes more sense to me now!

I tested, the following code works ( redirects).
But only if response.setStatus(301) is included.


String newurl = "http://www.newurl.com";
response.setContentType("text/html");
response.setStatus(301);
response.setHeader("Location", newurl);
...
}
There's a hole in the bucket, dear Liza, dear Liza, a hole in the bucket, dear liza, a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 862 times.
Similar Threads
Difference in status and error codes
core java communicates with servlet or jsp?
HTTP status in groovy?
"local inner classes"
class not found exception in japplet
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 01:24:39.