0% found this document useful (0 votes)
12 views10 pages

HTTPServletRequest HttpServletResponse

Uploaded by

roshan.prajapati
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views10 pages

HTTPServletRequest HttpServletResponse

Uploaded by

roshan.prajapati
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

HttpServletRequest

and
HttpServletResponse
HttpServletRequest interface

• HttpServletRequest interface extends the ServletRequest interface to provide


request information for HTTP servlets.

• The servlet container creates an HttpServletRequest object and passes it as an


argument to the servlet's service methods (doGet, doPost, etc).

• The HttpServletRequest breaks a request down into parsed elements, such as


request URI, query arguments and headers.

• Various get methods allow you to access different parts of the request.

 Request-URI

 Parameters

 Attributes
1) requestURI:- The requestURI deals with the URL sent by the browser.

For example:

http://localhost:8080/MyWebApplication/personal/info/top.html?info=intro
GetRequestURI -
• String uri = request.getRequestURI();
/MyWebApplication/personal/info/top.html
• String contextPath = request.getContextPath(); GetContextPath - /MyWebApplication

• String servletPath = request.getServletPath(); GetServletPath - /personal


GetPathInfo - /info/top.html
• String pathInfo = request.getPathInfo();
GetPathTranslated - /www/docs/info/top.html
HttpServletResponse
• The HttpServletResponse interface extends the ServletResponse interface
to provide HTTP-specific functionality in sending a response.
• HttpServletResponse helps us to send data back to web browser. e.g. set
cookies, session, data, etc.

• For example, it has methods to access HTTP headers and cookies.

• The servlet container creates an HttpServletResponse object and passes it


as an argument to the servlet's service methods (doGet, doPost, etc).
Web.xml
• The welcome-file-list element of web-app is used to define a list of welcome files.
• Its sub element is welcome-file that is used to define the welcome file.
• A welcome file is the file that is invoked automatically by the server, if you don't specify any file name.

• By default server looks for the welcome file in following order:


<web-app>
1. welcome-file-list in web.xml
....
2. index.html
<welcome-file-list>
3. index.htm
<welcome-file>home.html</welcome-file>
4. index.jsp
<welcome-file>default.html</welcome-file>
If none of these files are found, server renders 404 error. </welcome-file-list>

</web-app>
• Establishing aliases: associate servlet name to actual path of
servlet (fully qualified path of Servlet)
• Mapping: associates a URL to a servlet name
<servlet>
<servlet-name>Demo</servlet-name>
<servlet-class>com.tech.Demo</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Demo</servlet-name>
<url-pattern>/Welcome</url-pattern>
</servlet-mapping>

You might also like