|
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
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 |
|||
Advertise here or at any positions around our site send a mail to info@walkinsforum.com
|
« Next Oldest | Next Newest »
|
![]() |
|||||||
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
|
User(s) browsing this thread: 1 Guest(s)






![[-]](images/royal_red/collapse.gif)






