I am trying to get the complete URL from HttpServletRequest object. I got various ways of doing it. One of the way is to combine the requestURL with queryString. My situation is that there is a ? at the end with no query params. How do I identify that my URL has a ? at the end.
The URL is something like : http://www.xyz.com/path/id?
I need to consider ? as part of the id. (Client requirement :))
The code I am trying is:
public static String getFullURL(HttpServletRequest request) {
StringBuffer requestURL = request.getRequestURL();
String queryString = request.getQueryString();
if (queryString == null) {
return requestURL.toString();
} else {
return requestURL.append('?').append(queryString).toString();
}
}