RedirectWe can redirect users from one page to another. The basic syntax is:
response.sendRedirect "<another page>";
For example:
response.sendRedirect "john.JSP";
Let's imagine you have three clients: John, Mike and Joe. You want each client
go to his own page after login. You may use Redirect.
We need five pages. Let's create three pages: john.JSP, mike.JSP and joe.JSP
for the three clients. Keep the first.JSP as the same as the above. Modify second.JSP:
<%
String u=request.getParameter("user");
String p=request.getParameter("pass");
if ((u.equals("John")) && (p,equals("John123"))) {
response.sendRedirect "john.JSP";
}else{ if ((u.equals("Mike")) && (p.equals("Mike456"))) {
response.sendRedirect "mike.JSP";
}else{ if ((u.equals("Joe")) && (p.equals("Joe789"))) {
response.sendRedirect "joe.JSP";
}else{
out.println "<html><body>Sorry, invalid login</body></html>";
}
%>
Open first.JSP on web browser, enter user name and password. If the user name
and password match what we defined in second.JSP, then an user's page open.Otherwise,
display a message: "Sorry, invalid login".
|