goose84
goose84

Reputation: 292

How to get full URL in JSP

How would I get the full URL of a JSP page.

For example the URL might be http://www.example.com/news.do/?language=nl&country=NL

If I do things like the following I always get news.jsp and not .do

out.print(request.getServletPath()); out.print(request.getRequestURI()); out.print(request.getRequest()); out.print(request.getContextPath());

Upvotes: 4

Views: 22331

Answers (3)

gsm
gsm

Reputation: 2426

I found a solution. It may not be perfect solution. But it working solution.

String qs = request.getQueryString();
String foo = request.getRequestURL().toString()+"?"+qs;

Upvotes: 0

Manoj Kumar
Manoj Kumar

Reputation: 757

Given URL = http:/localhost:8080/sample/url.jsp?id1=something&id2=something&id3=something

request.getQueryString();

it returns id1=something&id2=something&id3=something

See This

Upvotes: 6

Bozho
Bozho

Reputation: 597106

You need to call request.getRequestURL():

Reconstructs the URL the client used to make the request. The returned URL contains a protocol, server name, port number, and server path, but it does not include query string parameters.

Upvotes: 6

Related Questions