package org.kodejava.example.servlet;
import java.io.IOException;
import javax.servlet.Servlet;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ServletUrlInformation extends HttpServlet implements Servlet {
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
//
// Getting servlet request URL
//
String url = request.getRequestURL().toString();
//
// Getting servlet request query string.
//
String queryString = request.getQueryString();
//
// Getting request information without the hostname.
//
String uri = request.getRequestURI();
//
// Below we extract information about the request object path
// information. We extract the protocol user, server and and its
// assigned port number. We extract our application context path,
// servlet path, path info and the query string information. If we
// combaine all the information below we'll get someting equals to
// the request.getRequestURL().
//
String scheme = request.getScheme();
String serverName = request.getServerName();
int portNumber = request.getServerPort();
String contextPath = request.getContextPath();
String servletPath = request.getServletPath();
String pathInfo = request.getPathInfo();
String query = request.getQueryString();
}
}
Download Hundreds of Complimentary Industry Resources
Get hundreds of popular Industry magazines, white papers, webinars, podcasts, and more;
all available at no cost to you. With more than 600 complimentary offers, you'll find
plenty of titles to suit your professional interests and needs.
Click Here and Sign up today!