Jonathan
Jonathan

Reputation: 3024

How to retrieve URL with parameters from a servlet?

If a user goes to profile?id=20, using request.getPathInfo() just returns /profile. Is there a way to retrieve the whole URL with parameters?

The reason I need to know this is because I want to forward the user back to the exact same page they came from after invoking a command, for example a friend request command.

Upvotes: 0

Views: 207

Answers (1)

BalusC
BalusC

Reputation: 1108632

The query string is not part of the path info.

You need to get it by HttpServletRequest#getQueryString().

String queryString = request.getQueryString();
// ...

And then compose the new URL yourself based on the parts.

By the way, I don't see why you would need it in a forward as the initial URL would remain the same. Perhaps you're confusing it with redirect?

Upvotes: 2

Related Questions