Submitted by heartin on Sat, 03/21/2015 - 09:21
We can configure a set of default file names to be loaded when request is made to a directory path using the DDs <welcome-file-list> element. Each file can be put inside a <welcome-file> element. The file can be a servlet mapping path, a jsp or even a static html file.
Submitted by heartin on Fri, 03/20/2015 - 13:33
ServletResponse Interface
ServletResponse encapsulates basic properties of a response independent of protocol and provide output streams to write content to client, independent of protocol.
There are two response streams
-
Java.io.OutputStream for binary data
-
Java.io.writer for character data
Note:
Submitted by heartin on Fri, 03/20/2015 - 13:23
ServletRequest Interface
Below methods work with the metadata properties carried by requests:
-
String getCharacterEncoding()
-
Int getContentLength()
-
String getContentType()
-
Enumeration getLocales()
-
Locale getLocale()
-
String getProtocol () E.g. HTTP/1.1
-
String getScheme() E.g.: http, https, ftp etc.
Submitted by heartin on Fri, 03/20/2015 - 13:14
There are four main entities involved in the HTTP request-response model:
- Client
- Web container
- Request
- Response
We will learn about request and response here.
Container provides us with two objects corresponding to request and response, encapsulating the request details and an empty response object when a request is received. These object interfaces also contain many convenience methods. These are passed through the service method of the servlet, which will then pass to us through the doXXX methods.
Submitted by heartin on Fri, 03/20/2015 - 12:02
Filters are pluggable classes that stand between the client and a target component (like a servlet or JSP), within a web application. We can do pre or post processing of request/response data while it is coming from client to a servlet or from the servlet back to a client.
Create a Servlet TargetServlet with URL Pattern as “/TargetServlet” and print some content to console from its doGet method. Code for TargetServlet is given in the end.
Now create a filter that will have the same url pattern for the servlet.
Pages