Get complete URL address on address bar of browser
-
I want to get complete URL address is displaying on address bar of browser. Example http://wwww.eshop.com/ShowMember?name=Peter White&id=123 I use JSP and Serlet to create web application. In above exmaple : ShowMember is a serlet http://wwww.eshop.com/ShowMember?name=Peter White&id=123 : display a JSP page on browser that is invoked by ShowMember Serlet
-
I want to get complete URL address is displaying on address bar of browser. Example http://wwww.eshop.com/ShowMember?name=Peter White&id=123 I use JSP and Serlet to create web application. In above exmaple : ShowMember is a serlet http://wwww.eshop.com/ShowMember?name=Peter White&id=123 : display a JSP page on browser that is invoked by ShowMember Serlet
Your message is not very clear, please try and explain what is not working. I would also suggest you move this to the Web Development[^] forum, as your question appears to be concerned with Web issues rather than Java.
It's time for a new signature.
-
I want to get complete URL address is displaying on address bar of browser. Example http://wwww.eshop.com/ShowMember?name=Peter White&id=123 I use JSP and Serlet to create web application. In above exmaple : ShowMember is a serlet http://wwww.eshop.com/ShowMember?name=Peter White&id=123 : display a JSP page on browser that is invoked by ShowMember Serlet
It depends a bit on how the page was called, but for as far as I know you can't get the complete URL simply by one call. You will need to construct it yourself as follows:
String url = request.getScheme() + "://" +
request.getServerName() + "/" +
request.getContextPath() + "/" +
request.getServletPath() +
(request.getQueryString() != null ? "?" + request.getQueryString() : "");I haven't done a code check but this should work presuming you are in the servlet or JSP file and have the HttpServletRequest object available as 'request'. Which should be the default for JSP files and the .get() and .post() members in any servlet.
-
It depends a bit on how the page was called, but for as far as I know you can't get the complete URL simply by one call. You will need to construct it yourself as follows:
String url = request.getScheme() + "://" +
request.getServerName() + "/" +
request.getContextPath() + "/" +
request.getServletPath() +
(request.getQueryString() != null ? "?" + request.getQueryString() : "");I haven't done a code check but this should work presuming you are in the servlet or JSP file and have the HttpServletRequest object available as 'request'. Which should be the default for JSP files and the .get() and .post() members in any servlet.
http://wwww.eshop.com/ShowMember?name=Peter White&id=123 : display a JSP page on browser which is called by ShowMember Serlet But the follwing code will return http://wwww.eshop.com/ShowMember.jsp?name=Peter White&id=123 String url = request.getScheme() + "://" + request.getServerName() + "/" + request.getContextPath() + "/" + request.getServletPath() + (request.getQueryString() != null ? "?" + request.getQueryString() : ""); I want to get the Serlet which called the JSP page which mean the address does not contain ".jsp"
-
http://wwww.eshop.com/ShowMember?name=Peter White&id=123 : display a JSP page on browser which is called by ShowMember Serlet But the follwing code will return http://wwww.eshop.com/ShowMember.jsp?name=Peter White&id=123 String url = request.getScheme() + "://" + request.getServerName() + "/" + request.getContextPath() + "/" + request.getServletPath() + (request.getQueryString() != null ? "?" + request.getQueryString() : ""); I want to get the Serlet which called the JSP page which mean the address does not contain ".jsp"
You could replace the getContextPath() and getServletPath() with getRequestURL() this should provide the url part after the domain up to the query string.
-
You could replace the getContextPath() and getServletPath() with getRequestURL() this should provide the url part after the domain up to the query string.
-
I tried it but it only return the address of JSP page which is called by Serlet. I want to get the Serlet which called this JSP Page
How do you forward the call from the Servlet to the JSP, are you doing this with the RequestDispatcher.forward() or by a response.sendRedirect()? If you are using the sendRedirect it is impossible to get the path of the servlet, as this is lost by a secondary client call to the JSP page.