javaservletsforwardingrequestdispatcher

different url after calling a servlet


I have A servlet that does some stuff, when it has done puts some things in the request and after calls another servlet which in turn calls a jsp page. I write the code:

first servlet (InserisciLezione)

            request.getRequestDispatcher("/TakeDates").forward(request, response);

second servlet (TakeDates)

 RequestDispatcher dispatcher = request
            .getRequestDispatcher("GestioneCalendario.jsp");
    dispatcher.forward(request, response);

This works properly but the problem is that in the url of the page I have yet:

 http://localhost:8080/Spinning/InserisciLezione?data=20-02-2013

and If I refresh the page the first servlet is called again and I don't want this. I would like to have

 http://localhost:8080/Spinning/GestioneCalendario.jsp

Why? thanks in advance!


Solution

  • If my memories are good (it's been a long time I didn't use raw servlets), you should use a redirect rather than a forward.

    You can use the response.sendRedirect(url) method.