Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

response.Status codes

 
Lida tatsol
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

Are response.Status codes included in the exam?

( for example response.SC_ACCEPTED etc)
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Lida tatsol
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Lida tatsol
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
 
Lida tatsol
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
...
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic