A servlet container breaks up the requesting URL into convenientcomponents for the servlet. The standard API does not require theoriginal requesting URL to be saved and therefore it is not possibleto get the requesting URL exactly as the
client sent it. However, afunctional equivalent of the original URL can be constructed. Thefollowing example assumes the original requesting URL is:
http://hostname.com/mywebapp/servlet/MyServlet/a/b;c=123?d=789
The most convenient method for reconstructing the original URL is touse
ServletRequest.getRequestURL(), which returns all but thequery string. Adding the query string reconstructs an equivalent ofthe original requesting URL:
If the hostname is not needed,
ServletRequest.getRequestURI()should be used:
// /mywebapp/servlet/MyServlet/a/b;c=123?d=789
public static String getUrl2(HttpServletRequest req) {
String reqUri = req.getRequestURI().toString();
String queryString = req.getQueryString(); // d=789
if (queryString != null) {
reqUri += "?"+queryString;
}
return reqUri;
}
The original URL can also be reconstructed from more basic componentsavailable to the servlet:
// http://hostname.com:80/mywebapp/servlet/MyServlet/a/b;c=123?d=789
public static String getUrl3(HttpServletRequest req) {
String scheme = req.getScheme(); // http
String serverName = req.getServerName(); // hostname.com
int serverPort = req.getServerPort(); // 80
String contextPath = req.getContextPath(); // /mywebapp
String servletPath = req.getServletPath(); // /servlet/MyServlet
String pathInfo = req.getPathInfo(); // /a/b;c=123
String queryString = req.getQueryString(); // d=789
// Reconstruct original requesting URL
String url = scheme+"://"+serverName+":"+serverPort+contextPath+servletPath;
if (pathInfo != null) {
url += pathInfo;
}
if (queryString != null) {
url += "?"+queryString;
}
return url;
}
分享到:
相关推荐
that target a single node (for example, all nodes in the botnet might be commanded by the attacker to send a TCP SYN message to the target, which might result in a TCP SYN flood attack at the target)...
Displaying inventory items in the UI 186 ■ Equipping a key to use on locked doors 188 ■ Restoring the player’s health by consuming health packs 190 8.5 Summary 191 STRONG FINISH ......................
In your browser—getting the post URL 60 Getting the post title 60 Getting the description 60 Getting the media type 62 Getting the post topic 62 In your browser—title, description, and topic ...
that had taken place in a landmark since designation and determining the use of the landmark. Effecting changes in landmark structures is not only wholly possible, but has been constant and widespread...
Android, the next-generation open mobile platform from Google and the Open Handset Alliance, is poised to become a significant player in the mobile device market. The Android platform gives developers...
Use the search field in the nav bar to search all of the CommonsWare books to see what they hold! Key Android Concepts Choosing Your Development Toolchain Tutorial #1 - Installing the Tools Android ...
and download the data in a secure way plays an important role, as users are nowadays performing these actions on all types of devices, including e.g. smartphones. Signing and encryption of the ...
Although a system having less than 2 GB of physical memory can be booted using the /3G switch, in most cases this is ill-advised. If you restart with the 3 GB switch, also known as 4-Gig Tuning, the ...
In the Beginning, There Was the Root, And It Was Good Permissions, Instrumentations, and Applications (Oh My!) Your Application Does Something, Right? Achieving the Minimum Version=Control ...
In addition to the Perl-compatible matching function, PCRE contains an alternative matching function that matches the same compiled patterns in a different way. In certain circumstances, the ...
headings contained in the answer.The authors and I would like to think that this information and the questions they inspire will provide insight and perspective to help you solve problems that go ...
You may register a different individual by sending email requesting a change in registration to support@recover4all.com. The newly registered individual, and not the previously registered individual...
Requesting a Structure Containing the Device Path Name 298 Extracting the Device Path Name 301 Closing Communications 302 Contents ix Obtaining a Handle 303 Requesting a Communications Handle 303 ...
JDK 7 is a superset of JRE 7, and contains everything that is in JRE 7, plus tools such as the compilers and debuggers necessary for developing applets and applications. JRE 7 provides the libraries, ...
a conversation is contained in the IMP software. It is thus not possible to query an IMP about the state of a link (although it might be possible to query an IMP about the recent history of a link ...
After extracting your zip-file, place the extracted DLL-file in the directory of the program that is requesting the file. Make sure to use a 32bit DLL-file for a 32bit program, and a 64bit DLL-file ...
At the end, you will enhance your development skills by getting to grips with the integration of RESTful APIs, building microservices, and doing reactive programming using Spring, as well as ...
which has one static part and two partial reconfigurable modules, ICMP and HTTP. A Web Client sends different packets to the system requesting different services. These packets’ type information are...
What happens when I find a bug in the parsing code or perhaps a new node is added to the XML? We’d have to go through all the different places and make change. By having a single point for parsing ...
For file uploads, the file extension is precisely controlled in a list defined in the config.ascx file. It is possible to define different folder locations for each file type. Attention :...