iTech College - Internet Technology, Online Education, E-Learning, Technician Training, Tech Tutorials, Distance Education, Virtual Learning JSP Course: Redirect - www.itechcollege.com JSP Course: Redirect - www.itechcollege.com
Online Degrees Scholarships & Fellowships Internships Student Financial Aid Study Abroad Itech Bookstore
Free Courses
HTML
JavaScript
CSS
ASP
PHP
JSP
ASP.NET
SQL
AJAX
FTP
XML
Career Center
Job List
Web Jobs
Student Jobs
Computer Jobs
Engineer Jobs
Developer Jobs
Job Search
Resume Writing
Job Interview
Salary Info


itech > courses > JSP > Redirect

Redirect

We 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".

  Back to Index Page
Next Page >>   Introduction
JSP Tags and Include File
println and getParameter
The If Statement
For Loop
Redirect
Session
Use Database
JSP syntax
Scripting elements
Actions
 

JSP Books
JSP Jobs



Bookmark:  del.icio.us digg facebook Reddit Mixx BlinkList Fark Furl NewsVine Simpy Spurl Segnalo Technorati blogmarks Google YahooMyWeb Windows Live



JSP Course: Redirect - www.itechcollege.com
Copyright ©2008, itechcollege.com. All rights reserved
iTechCollege | About iTech | Contact iTech