0

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!

Martina
  • 1,852
  • 8
  • 41
  • 78
  • Maybe you want to use `Send-Redirect`. It is not the same than forwarding the request (it just tells the browser to load the new page) – SJuan76 Feb 13 '13 at 11:12

2 Answers2

2

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.

Ryan M
  • 18,333
  • 31
  • 67
  • 74
1

The RequestDispacher interface provides the facility of dispatching the request to another resource it may be html, servlet or jsp.This interface can also be used to include the content of antoher resource also. It is one of the way of servlet collaboration.

In your case ,you are getting this

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

because of this servlet

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

Page refresh will always redirect you to that url by which servlet you have used. Its like calling an ajax event.

Anyway I can see you dont need to use forward method,try to use

response.sendRedirect(your_url);
arvin_codeHunk
  • 2,328
  • 8
  • 32
  • 47