iTech College - Internet Technology, Online Education, E-Learning, Technician Training, Tech Tutorials, Distance Education, Virtual Learning JSP Course: The If Statement - www.itechcollege.com JSP Course: The If Statement - 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 > The If Statement

The If Statement

Let's modify the above two pages:

first.JSP:

<html> 
<body> 
<form action="second.JSP" method="post">
User Name: <input type="text" name="user">
Password: <input type="password" name="pass">
<input type="submit" value="Send Query String">
</form>
</body> 
</html>

second.JSP:

<html>
<body>
<%
String u=request.getParameter("user");
String p=request.getParameter("pass");
if ((u.equals("John")) && (p.equals("John123"))) {
out.println "Hi" + u + ", your login is valid.";
}else{
out.println "Sorry, invalid login";
}
%>
</body>
</html>

Open first.JSP on web brower, enter some values as user name and password in the boxes, then submit. You will see, if you entered "John" for the user name and "John123" for the password, then the output on second.JSP is:

Hi John, your login is valid

Otherwise, you will see the message:

Sorry, invalid login

The basic syntax of "If... then..." is:

if (...) {
...
}

You can use "else" or "else if " to make more choices:

if (...) {
...
}else if (...) {
... 
}else{
...
}
  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: The If Statement - www.itechcollege.com
Copyright ©2008, itechcollege.com. All rights reserved
iTechCollege | About iTech | Contact iTech