Share on Google+Share on Google+

Interface HttpServletRequest methods

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

Advertisements

Posted on: March 23, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial 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.