Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the request url from HttpServletRequest [duplicate]

Say i make a get request like this:

GET http://cotnet.diggstatic.com:6000/js/loader/443/JS_Libraries,jquery|Class|analytics|lightbox|label|jquery-dom|jquery-cookie?q=hello#frag HTTP/1.0
Host: cotnet.diggstatic.com:6000

My servlet takes request like this: HttpServletRequest req;

When i debug my server and execute, i get the following:

req.getRequestURL().toString() = "http://cotnet.diggstatic.com:6000/js/loader/443/JS_Libraries,jquery%7cClass%7canalytics%7clightbox%7clabel%7cjquery-dom%7cjquery-cookie"
req.getRequestURI() = "/js/loader/443/JS_Libraries,jquery%7cClass%7canalytics%7clightbox%7clabel%7cjquery-dom%7cjquery-cookie"
req.getQueryString() = "q=hello"

How does one get the fragment information ? Also, when i debug the request, i see a uri_ field of type java.net.URI which has the fragment information. This is exactly what i want. How can i get that ?

like image 201
pdc Avatar asked May 18 '10 20:05

pdc


People also ask

How do I find my URI request?

The Method request. getRequestURI() returns URI with context path. For example, if the base URL of an application is http://localhost:8080/myapp/ (i.e. the context path is myapp), and I call request. getRequestURI() for http://localhost:8080/myapp/secure/users , it will return /myapp/secure/users .

Which method is used to retrieve the values from HttpServletRequest?

The HttpServletRequest interface provides the getCookies method to obtain an array of cookies that are present in the request. This method returns null if no cookies were sent. The cookies are data sent from the client to the server on every request that the client makes.

What is the difference between HttpServletRequest and ServletRequest?

ServletRequest provides basic setter and getter methods for requesting a Servlet, but it doesn't specify how to communicate. HttpServletRequest extends the Interface with getters for HTTP-communication (which is of course the most common way for communicating since Servlets mostly generate HTML).

Which method of HttpServletRequest returns the name of the HTTP method with which the request was made?

getMethod. Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT.


1 Answers

"The fragment identifier functions differently than the rest of the URI: namely, its processing is exclusively client-side with no participation from the server." Wikipedia about the Frament Identifiert

For further reference see the RFC 2394 Section 4.1

like image 172
2 revs Avatar answered Oct 05 '22 06:10

2 revs