0
votes

I have a situation where i have two jsp pages (page1.jsp,page2.jsp) plus one index.jsp page...The user will call index.jsp page..Now,if he/she hits the url with parameter ( http://localhost:8080/Test/Index.jsp?type=1) then he should be redirected to page1 and if he hits without parameter (http://localhost:8080/Test/Index.jsp ) then it should take him to page 2..

How to achieve this? I am using response.sendRedirect to do this...

Appreciate your help..Thanks

2

2 Answers

1
votes

Check for the presence of the type parameter in your servlet.

if("1".equals(request.getParameter("type"))
{
     response.sendRedirect("Page1");
}
else
{
     response.sendRedirect("Page2");
}
0
votes

You should get type attribute from request object then if this index equals 1 redirect to page1.jsp otherwise page2.jsp

String typeVal = (String)request.getParameter("type");
if ("1".equals(typeVal)) {
     response.sendRedirect("Page1.jsp");
} else {
     response.sendRedirect("Page2.jsp");
}