Home Tutorial Java Servlet HttpServletRequest Example

 
 

Share on Google+Share on Google+
HttpServletRequest Example
Posted on: March 24, 2010 at 12:00 AM
Advertisement
In this tutorial you will see some methods of the HttpServletRequest.

Code:

package roseindia
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.System.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HttpServletRequestExample extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><head><title>Header Information</title></head><body>");
out.println("Remote Address : "+request.getRemoteAddr()+"<br>");
out.println("Remote HOst : "+request.getRemoteHost()+"<br>");
out.println("Remote Port : "+request.getRemotePort()+"<br>");
out.println("Server Name : "+request.getServerName()+"<br>");
out.println("Server Port : "+request.getServerPort()+"<br>");
out.println("Servlet Context : "+request.getServletContext()+"<br>");
out.println("Servlet Path : "+request.getServletPath()+"<br>");
out.println("</body></html>");
}
}

Output:

Remote Address : 127.0.0.1
Remote HOst : 127.0.0.1
Remote Port : 2830
Server Name : localhost
Server Port : 8080
Servlet Context : org.apache.catalina.core.ApplicationContextFacade@10d386d
Servlet Path : /HttpServletRequestExample

Advertisement

Related Tags for HttpServletRequest Example :


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 24, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com