JaiswalTraining

Get the online training



Corejava Servlet Jsp  Php  Hibernate  Ajax Web Service   Ejb2.1 Ejb3.0 Struts Struts2  JPA Spring Ibatis   JSF    JSF2.0  CoreJavaDesignPattern    Jquery  Flex J2EE-Design-Patterns  Jboss7  Maven  Contact Me                                                                                                                                                                        
            IGNOU SMU PTU Project                                           Training                                                                                                                              
              

Contact Us  0091- 9210721663         jaiswaltraining@gmail.com








Corejava
Servlet
Jsp
Php
Hibernate
Ajax
Web Service
Ejb2.1
Ejb3.0
Struts  
Struts2
JPA
Spring
Ibatis
JSF
JSF2.0
CoreJavaDesignPattern
Jquery
Flex
J2EE-Design-Patterns
Jboss7
Maven







Generating the Server Response: HTTP Status Codes

  • Format of the HTTP response

  • How to set status codes

  • What the status codes are good for

  • Shortcut methods for redirection and error pages

  • A servlet that redirects users to browser-specific pages

  • A front end to various search engines


HTTP 1.1 codes falls into five general categories

  •   100-199
    •  codes in the 100s are informational, indicating the client should respond with some other action.
  •   200-299
    •  values in the 200s signify that request was successful.
  •   300-399
    •  values in the 300s are used for files that have moved and usually include a Location header indicating the new address.
  •   400-499
    •  indicates error by client.
  •  500-599
    •  indicates error by server
  • 200(Ok)
    •   A value of 200(SC_OK) means that everything is fine; the document follows for GET and POST request. This status is the default status for servlet.
  • 302(Found)  
    • The value is similar to 301, except that in principal the URL given by Location header should be interpreted as temporary replacement not permanent one. 
  •   404(Not Found) 
    •   The infamous 404(SC_NOT_FOND) status tells the client that no resource should be found at that address. This value is the standard “no such page” response.

 

• public void sendError(int code, String message)

    The sendError method sends a status code (usually 404) along with a short message that is automatically formatted inside an HTML document and sent to the client.

• public void sendRedirect(String url)

The sendRedirect method generates a 302 response along with a Location header giving the URL of the new document. With servlets version 2.1, this must be an absolute URL. In version 2.2, either an absolute or a relative URL is permitted and the system automatically translates relative URLs into
absolute ones before putting them in the Location header.

Setting a status code does not necessarily mean that you don’t need to return a document.