Enter your email address:

Delivered by FeedBurner


Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Redirect page using jsp to another page
11-28-2011, 06:49 PM (This post was last modified: 11-28-2011 06:49 PM by admin.)
Post: #1
Redirect page using jsp to another page
How to redirect a page to another page with in jsp when some conditions are satisfied In this example first create a html page(login.html) with two boxes
username and password if login is correct it redirect to somepage.jsp if password is wrong it return back to login page
Note:Create database “s2sgateway” in mysql as i did in mysql(use any database) and create a table named “admin” with username and password
Login.html

<html><head>
<script type="text/javascript">
function check()
{
if(document.f.un.value=="" || document.f.pw.value=="")
{
alert("Enter details");
return false;
}
else
{
return true;
}
}
</script>
</head>
<body>
<form name="f" method="get" action="login.jsp">
<font color="red">
<marquee align="left" bgcolor="blue">LOGIN
FORM</marquee>
<br><br>
<center>
USERNAME: <input type="text" name="un"></center>
<center>PASSWORD:
<input type="password" name="pw"></center>
<center>
<input type="submit"
value="SIGN IN" onclick="return check()" /></center></font>
</form>
</body></html>
Now create action page login.jsp
<%@ page language="java"
import="java.sql.*,java.util.*"%>
<%String name=request.getParameter("un");
String pwd=request.getParameter("pw");
try{
Connection
con=DriverManager.getConnection
("jdbc:mysql://localhost/s2sgateway","username",
"password");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from admin where username='"+name+"'");
while(rs.next())
{
if((rs.getString(1).equalsIgnoreCase(name))&&(r
s.getString(2).equalsIgnoreCase(pwd)))
{
out.println("WELCOME,Webmaster");
response.sendRedirect("somepage.jsp");

}
else
{
response.sendRedirect("login.html");
}
}
}catch(Exception e)
{
out.println(e);
}
%>

Here once the user verified then the page is redirected to another page.Happy coding
Find all posts by this user
Add Thank You Quote this message in a reply
Advertise here or at any positions around our site send a mail to info@walkinsforum.com
Post Reply 


[-]
Share/Bookmark (Show All)
Facebook Linkedin Technorati Twitter Digg MySpace Delicious

Possibly Related Threads...
Thread: Author Replies Views: Last Post
Big Grin In Tomcat jsp page is not refreshing rajasri 0 199 12-19-2011 06:11 PM
Last Post: rajasri
Thumbs Up Display combo box value/Database value on same JSP page rajasri 0 326 12-19-2011 04:57 PM
Last Post: rajasri
Its My Birthday! Display database value in jsp page rajasri 0 609 12-14-2011 11:43 AM
Last Post: rajasri
Video simple update query in jsp page rajasri 0 1,067 12-14-2011 11:36 AM
Last Post: rajasri
Shocked update using parameters in jsp page rajasri 0 434 12-14-2011 11:34 AM
Last Post: rajasri
Big Grin using session to protect a page in jsp rajasri 0 583 12-13-2011 12:17 AM
Last Post: rajasri
Video Display current time and date in your Jsp page rajasri 0 957 12-12-2011 11:56 PM
Last Post: rajasri
Star Getting number of rows in jsp page rajasri 0 587 12-12-2011 11:53 PM
Last Post: rajasri
Star Read data from xml and show in jsp page project download rajasri 0 951 12-12-2011 11:30 PM
Last Post: rajasri
Bug Print current time using java in jsp page rajasri 0 620 12-12-2011 11:20 PM
Last Post: rajasri

Forum Jump:


User(s) browsing this thread: 1 Guest(s)