Full Java User Login code

Source: Internet
Author: User

Full Java User Login code

Login. Web effects phttp://www.111cn.net/web effects p.html target=_blank >jsp Tutorial login, enter the database tutorial in the saved user name and password why not jump to the login_success.jsp page?
There are three fields in the person list: Id,name,password.


LOGIN.JSP:
<%@ page contenttype= "text/html;charset=gb2312"%>

<body>
<center>


<form action= "login_conf.jsp" method= "POST" >
<table width= "50%" border= "1" >
<tr>
<TD colspan= "2" > User login </td>
</tr>

<tr>
<td> User name:</td>
<td><input type= "text" name= "id" ></td>
</tr>

<tr>
<td> Secret &nbsp;&nbsp; Code:</td>
<td><input type= "password" name= "password" ></td>
</tr>

<tr>
<TD colspan= "2" >
<input type= "Submit" value= "Login" >
<input type= "reset" value= "reset" >
</td>
</tr>
</table>
</form>
</body>

LOGIN_CONF.JSP:
<%@ page contenttype= "text/html;charset=gb2312"%>
<%@ page import= "java.sql.*"%>

<body>

<% out.print ("oksssss");
String dbdriver = "Oracle.jdbc.driver.oracledriver";
String dburl = "Jdbc:oracle:thin: @localhost: 1521:js";
String dbuser = "Scott";
String Dbpassword = "Tiger";
Connection conn =null;
PreparedStatement PS Tutorial TMT =null;
ResultSet Rs =null;

%>
<%
  Boolean flag = false;
String id=request.getparameter ("id");
String password = reques T.getparameter ("password");
%>
<%
String sql = select name from person values id =? and password =? ";
 //Out.print (flag);
  Try
  {
  class.forname (dbdriver);
Conn=drivermanager.getconnection (Dburl,dbuser, Dbpassword);
pstmt=conn.preparestatement (SQL);
Pstmt.setstring (1,id);
Pstmt.setstring (2,password);
Rs=pstmt.executequery ();
if (Rs.next ())
{

Flag=true;
Session.setattribute ("Uname", rs.getstring (1));
}
Else
{
Request.setattribute ("Err", "wrong username or password!") ");
}
Rs.close ();
Pstmt.close ();
Conn.close ();
}
catch (Exception e)
{
}
%>
<%
if (flag)
{

%>
<jsp:forward page= "login_success.jsp"/>
<%
}
Else
{
%>
<jsp:forward page= "login.jsp"/>
<%
}
%>
</body>


LOGIN_SUCCESS.JSP:
<%@ page contenttype= "text/html;charset=gb2312"%>

<body>

<%
if (Session.getattribute ("uname")!=null);
{
%>
<font color= "#ff0000" size= "a" >
<%=session.getattribute ("uname")%>
</font>
Visit MLDN message!

<%
}
Else
{
Response.setheader ("Refresh", "2;url=login.jsp");
%>
You have not logged in, please <a href= "login.jsp" > Login! </a>

<%
}
%>

</body>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.