| Author |
response.Status codes
|
Lida tatsol
Greenhorn
Joined: Oct 23, 2004
Posts: 4
|
|
Hello everyone, Are response.Status codes included in the exam? ( for example response.SC_ACCEPTED etc)
|
 |
Nicholas Cheung
Ranch Hand
Joined: Nov 07, 2003
Posts: 4982
|
|
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
|
SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
|
 |
Lida tatsol
Greenhorn
Joined: Oct 23, 2004
Posts: 4
|
|
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
Joined: Nov 07, 2003
Posts: 4982
|
|
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
Joined: Oct 23, 2004
Posts: 4
|
|
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
Joined: Oct 23, 2004
Posts: 4
|
|
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); ... }
|
 |
 |
|
|
subject: response.Status codes
|
|
|