-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServletTest.java
61 lines (51 loc) · 1.98 KB
/
ServletTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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 ServletTest extends HttpServlet {
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.
//
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();
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
pw.print("Url: " + url + "");
pw.print("Uri: " + uri + "");
pw.print("Scheme: " + scheme + "");
pw.print("Server Name: " + serverName + "");
pw.print("Port: " + portNumber + "");
pw.print("Context Path: " + contextPath + "");
pw.print("Servlet Path: " + servletPath + "");
pw.print("Path Info: " + pathInfo + "");
pw.print("Query: " + query);
}
}