完整java使用者登陸代碼

來源:互聯網
上載者:User

完整java使用者登陸代碼

login.網頁特效phttp://www.111cn.net/網頁特效p.html target=_blank >jsp教程登入,輸入資料庫教程中儲存的使用者名稱和密碼 為何不能跳轉到login_success.jsp頁面?
person表裡有三個欄位:id,name,password.


login.jsp:
<%@ page contenttype="text/html;charset=gb2312"%>
<html>
<body>
<center>


<form action="login_conf.jsp" method="post">
<table width="50%" border="1">
<tr>
<td colspan="2">使用者登入</td>
</tr>

<tr>
<td>使用者名稱:</td>
<td><input type="text" name="id"></td>
</tr>

<tr>
<td>密&nbsp;&nbsp;碼:</td>
<td><input type="password" name="password"></td>
</tr>

<tr>
<td colspan="2">
<input type="submit" value="登入">
<input type="reset" value="重設">
</td>
</tr>
</table>
</form>
</body>
</html>

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

<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教程tmt =null;
resultset rs =null;

%>
<%
  boolean flag = false;
string id=request.getparameter("id");
string password = request.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","錯誤的使用者名稱或密碼!");
}
rs.close();
pstmt.close();
conn.close();
  }
  catch(exception e)
  {
  }
%>
<%
  if(flag)
  {
   
%>
  <jsp:forward page="login_success.jsp"/>
<%
  }
  else
  {
%>
  <jsp:forward page="login.jsp"/>  
<%
  }  
%>
</body>
</html>


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

<body>

<%
  if(session.getattribute("uname")!=null);
  {
%>
  <h2>登入成功!</h2>
<h2>歡迎
<font color="#ff0000" size="12">
<%=session.getattribute("uname")%>
</font>
光臨mldn留言!</h2>

<%  
  }
  else
  {
  response.setheader("refresh","2;url=login.jsp");
 %>
  您還未登入,請先<a href="login.jsp">登入!</a>
 
 <% 
  }
%>

</body>
</html>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.