Tuesday, December 25, 2012

Basic Servlet Structure

1. Content Type:

  1. HTML: test/html
  2. XML:test/xml
  3. Spreatsheets: application/vnd.ms-excel
  4. JPEG:image/jpeg

Put the  setContentType line before any of the lines that use the  PrintWriter.

2. public void init()

The init method is called only when the servlet is first loaded, before the first request is processed. 
  1. redeployed servlet
  2. modify web.xml 

3. Note that the use of JavaScript for client-side validation does not remove the need for also doing this type of checking on the server. 
client side (JavaScript) <-> server side

Besides, clients can use  their own HTML forms, can manually edit URLs that contain  GET  data, and can disable JavaScript. 

4. check the empty input on server side





4.7 Automatically Populating Java Objects from Request Parameters

getParameterMap

java.util.Map<java.lang.String,java.lang.String[]> getParameterMap()
Returns a java.util.Map of the parameters of this request.Request parameters are extra information sent with the request. For HTTP servlets, parameters are contained in the query string or posted form data.
Returns:
an immutable java.util.Map containing parameter names as keys and parameter values as map values. The keys in the parameter map are of type String. The values in the parameter map are of type String array.









javax.servlet
Interface ServletResponse

javax.servlet.http
Interface HttpServletResponse

http://docs.oracle.com/javaee/5/api/javax/servlet/ServletResponse.html


No comments:

Post a Comment