Home Tutorial Java Servlet Httprequest Interface HttpServletRequest methods

 
 

Share on Google+Share on Google+
Interface HttpServletRequest methods
Posted on: March 23, 2010 at 12:00 AM
Advertisement
Here in this example you will see some set of method provided by the Interface HttpServletRequest.

Description:

The interface HttpServletRequest called from the javax.servlet.http package which extends the ServletRequest interface.The HttpServletRequest object created by the servlet container and passes as an argument to the servlet's service method ie doGet, doPost,etc.

Code Sample:

Servlet1.java

package package1;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Servlet1 extends HttpServlet {

protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();

out.println("<html>");
out.println("<head>");
out.println("<title>Servlet Servlet1</title>");
out.println("</head>");
out.println("<body>");

out.println("<h1>Servlet ContextPath : " + request.getContextPath() + "</h1>");
out.println("<h1>Servlet authentication scheme : " + request.getAuthType() + "</h1>");
out.println("<h1>Name of HTTP method with which this request was made :" + request.getMethod() + "</h1>");
out.println("<h1>Default locate for the server :" + request.getLocale() + "</h1>");

out.println("</body>");
out.println("</html>");

}
}

Output:

Servlet ContextPath : /Tutorial
Servlet authentication scheme : null
Name of HTTP method with which this request was made :GET
Default locate for the server :en_US

Advertisement

Related Tags for Interface HttpServletRequest methods:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: March 23, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com