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
Free Courses
HTML
JavaScript
CSS
ASP
PHP
JSP
C++
ASP.NET
SQL
AJAX
FTP
XML

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


Online Education, Online Training for Your Job, Distance Education, E-learning Programs for Your Career!Online Colleges, Online Universities, E-learning & Distance Education for Your Career! Easy Job Training & Online Courses.


   Email A Friend  
 
Earn Online Degree
for Your Job
I found a job after I earned an online degree!
Online classes for finding a Job. Online College, Online University, Degrees, E-learning school, online certificate Earn your
online degree now!
Online Training
for Good Job
Why I work so hard but earn so little? Why I cannot find a high paying job?
Online training for a Good Jobs. Online Degree, E-learning school, online certificate Go to
online school now!

Copyright ©2024, itechcollege.com. All rights reserved
iTechCollege | About iTech | Contact iTech