0

In my jsp I have a form that contains :

<form name="myForm" action="/ServletOne">
<input type="text" name="username">
<input type="password" name="password"/>
</form>

In ServletTwo, I have :

String username = request.getParameter("username");
String password = request.getParameter("password");

At the end of ServletOne, I need to redirect to ServletTwo. So I tried :

String redirectURI =  "/ServletTwo?"+ request.getQueryString();
response.sendRedirect(redirectURI);

But request.getQueryString() returns null. So How could I redirect to "ServletTwo" without losing username and password parameters, knowing that ServletOne and ServletTwo are not in the same web appplication. And I don't have the right to modify the code of ServletTwo.

Thanks in advance

tun_eng
  • 133
  • 1
  • 3
  • 13

1 Answers1

0

You can simply right following code in servletone:

getServletContext().getRequestDispatcher("/ServletTwo").forward(request, response);
vicky
  • 561
  • 1
  • 7
  • 17
  • I tried this : getServletContext().getContext("/mysecondwebapp").getRequestDispatcher("/ServletTwo").forward(request, response); Is there a difference between what I did and your response ? – tun_eng Jan 30 '13 at 08:53
  • Yes both have different redirections – vicky Jan 30 '13 at 08:59
  • check this out for details- http://www.mysamplecode.com/2011/06/java-servlet-redirect-vs-forward.html – vicky Jan 30 '13 at 09:01
  • If you got the answer then just rate my answer, so it can help other also. Thanks – vicky Jan 30 '13 at 09:02
  • I used : getServletContext().getContext("/mysecondwebapp").getRequestDispatcher("/Servlet‌​Two").forward(request, response); because ServletTwo (which is in mysecondwebapp) is in not in the same webapp as ServletOne. Is this correct please ? – tun_eng Jan 30 '13 at 09:05
  • You should try and tell that its working in your case or not. – vicky Jan 30 '13 at 09:15
  • By default your case connot be achieved. You need to configure Tomcat first to enable exposing the **ServletContext** of the current webapp to other webapps. This is to be done by setting the **crossContext** attribute of **context.xml** to true. http://tomcat.apache.org/tomcat-7.0-doc/config/context.html – vicky Jan 30 '13 at 09:31
  • Reffer to this question: http://stackoverflow.com/questions/13435678/does-requestdispatcher-work-over-multiple-webapps-in-one-servlet-container – vicky Jan 30 '13 at 10:17