- Browser sends web request when
- user clicks on the hyperlink
- form post
- enters address in address bar and press enter - For form data in POST method, enctype attribute should be set as multipart-formdata
- Difference between GET and POST on : resource type, type of data,amount of data,visibility and caching
- Signature of method doXXXX is protected void and it throws ServletException, IOException
- ServletRequest defines getParameter(String Name), getParameterValues(String Name) and getParameterNames() which return String, String[] and Enumeration respectively.
- HttpServletRequest defines getHeader(String Name), getHeaders(String Name) and getHeaderNames() which return String, Enumeration and Enumeration respectively.
- getWriter on ServletResponse returns PrintWriter object and getOutputStream returns ServletOutputStream(extends OutputStream).
- Call to setContentType for setting the mimetype should be done on response object before getWriter or getOutputStream is invoked.
- Either getWriter or getOutputStream should be called. Mixing will result in IllegalStateException
- setHeader on response object sets the header. setIntHeader and setDateHeader similar functions. addHeader, addIntHeader and addDateHeader sets new value for same header if already exists. containsHeader which returns boolean returns true if the header is already set.
- Common headers are : Date, Expires, Last-Modified and Refresh
- sendRedirect on response object does a browser redirect. Calling redirect after response is committed (calling flush on writer) will cause IllegalStateException
- sendError(int errorcode) will send the error code in response header so that browser can display appropriate message(or web server sends appropriate contents).
- ServletContainer loads and instantiates servlet by calling Class.forName(...).new Instance(). To do this there should be a public constructor with no arguments. Having a default class with no constructor or a public class with some constructor having arguments(no default constructor) will error when accessed by client with 500 status.
- Two init methods. one takes ServletConfig and the other none. Overriding the one which takes parameter requires a call to super.init to store the config object. instead the GenericServlet's init method which takes parameter makes a call to the no argument init method. So, overriding the no argument init method takes care of everything. To get servletconfig in no arg method call, getServletConfig()
- Servlet not initialized at startup to reduce the startup time. However if large initialization is done then the first request for servlet will take long time. To prevent this servlet can be preinitialized at startup by the element in descriptor.
- ServletConfig class has getInitParameter and getInitParameterNames which return String and Enumeration respectively. It has getServletContext and getServletName methods.
- getResource on ServletContext return java.net.URL. call openStream on URL to get InputStream. Instead call getResourceAsStream to directly get Stream corresponding to resource.
- Limitation of getResource is that any URL for any active resource cannot be passed. This will result in security loophole. getResource on jsp file returns the source code of jsp and not the executed output.
Monday, October 23, 2006
My Notes for SCWCD
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment