-1

I have a URL like

www.abc.com/;jsessionid=53AA662D24A89922031913A6E85A005B

(sorry i can't specify my actual site name here, so using abc.com)

When the above url is hit, i want to strip ;jsessionid=53AA662D24A89922031913A6E85A005B from the above url in the back-end (in my servlet) and redirect to the actual url (in this example http://www.abc.com/).

I have tried many ways in my servlet to know whether the requested URL has 'jsessionid' or not, but I can't find a method that returns the full requested URL on HTTP request object

I have tried the following methods on the HTTP request object

  • getRequestURI()
  • getRequestURL()
  • getContextPath()
  • getPathInfo()

but they are not returning the full requested url with the jsessionid.

I have tried getParameter(), getParameterNames() but no help as the above url doesn't have ? before jsessionid.

Kate Gregory
  • 18,808
  • 8
  • 56
  • 85
user2478817
  • 41
  • 1
  • 1
  • 2
  • 1
    when specifying an 'example' site name like that, the standard practice is to use `example.com` rather than `abc.com` (the actual domain example.com is reserved for this use, whereas abc.com points to a real site, which obviously isn't yours) – Spudley Jun 17 '13 at 12:56
  • https://stackoverflow.com/questions/16675191/get-full-url-and-query-string-in-servlet-for-both-http-and-https-requests/16675399 – Phoenix Jan 10 '19 at 05:01
  • If none of those methods returns `;jsessionid=...` it has already been removed by the servlet container, whose job it is to manage the session. *Ergo* you don't have to do anything. – user207421 Aug 08 '23 at 05:32

2 Answers2

8

here is how you can retrieve the complete url above in your Servlet

 public void doGet(HttpServletRequest request, HttpServletResponse response)
                       throws IOException, ServletException {

               String url = request.getRequestURL().toString();
              System.out.println(url);
               }
grepit
  • 21,260
  • 6
  • 105
  • 81
  • Thank you for your reply.I have tried but didn't work. here i have taken the example: https://www.google.com/;jsessionid=53AA662D24A89922031913A6E85A005B in this link i want to retrieve the jsessionid value in my servlet. As the "?" is not there before the jsessionid i am not able to retrieve it. Can you please kindly help me how to retrieve it. – user2478817 Jun 13 '13 at 13:01
2
public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException {

    String jSessionId=request.getParameter("jsessionid");

    System.out.println("jSessionId:"+jSessionId);    
}
Mureinik
  • 297,002
  • 52
  • 306
  • 350