Here in this example you will see some set of method provided by the Interface HttpServletRequest.
Here in this example you will see some set of method provided by the Interface HttpServletRequest.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.
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>");
}
}
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