一个简单的JSP登陆代码

来源:互联网 发布:effective java mobi 编辑:程序博客网 时间:2024/06/04 23:36
 
源代码
   
一个简单的JSP登陆代码
08.7.12

<%@ page contentType="text/html; charset=GBK" %> <jsp:useBean id="Dl" scope="request" class="dlxx.Dl" />  <%@ page import="java.sql.*" %> <%@ page import="sun.jdbc.rowset.*;" %> <%request.setCharacterEncoding("GBK");%> <%//得到隐藏域的值 String doCreate = request.getParameter("doCreate"); String uname = request.getParameter("uname");String psw = request.getParameter("psw");if (doCreate==null){doCreate="false";} //这说明提交过来了数据 if (doCreate.equals("true")) { //执行增加操作,要判断主键是否重复-1,     CachedRowSet resultPage=null;    resultPage=Dl.getRowSet("select * from dl where    uname='"+uname+"'");     if (resultPage.next()){       resultPage=Dl.getRowSet("select * from dl where    uname='"+uname+"' and psw='"+psw+"'");     if (resultPage.next()){     //登陆成功处理     String tname=resultPage.getString("tname");     session.setAttribute("tname", tname);     session.setAttribute("uname", uname);    response.sendRedirect("index.htm");    return;    }      }      %> <script language="javascript">       alert("用户名或者密码错误!"); history.back();  </script>  <%   

    }    %>

<html> <head> <title>系统页面登陆</title> <META http-equiv=Content-Type content="text/html; charset=GBK"> <script language="JavaScript"    src="calendar.js"></Script>     <link href="images/server.css" rel="stylesheet" type="text/css">      <style type="text/css"> <!--  body,td,th { font-size: 12px;} a {font-size: 12px;} .input_1 {     BORDER-RIGHT: #c7c8c7 1px solid; BACKGROUND-POSITION: 50% top; BORDER-TOP: #c7c8c7 1px solid; FONT-SIZE: 12px; BACKGROUND-IMAGE: url(images/inputshow.gif); BORDER-LEFT: #c7c8c7 1px solid; COLOR: #7b7b7b; BORDER-BOTTOM: #c7c8c7 1px solid; BACKGROUND-REPEAT: repeat-x; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif } .style1 {color: #000000}    -->    </style>   <script language="javascript">  function checkInput() { if (document.dlym.uname.value==""){      alert("请输入用户名!");      document.dlym.uname.focus();      return false;}      if (document.dlym.psw.value==""){      alert("请输入密码!");      document.dlym.psw.focus();      return false;}     return true; } </script> </head> <body background="images/index_17.gif" leftmargin="000" topmargin="0"><form    name="dlym" method="POST" action="dlym.jsp" onSubmit="return checkInput();" >     <table width="100%" border="0" cellpadding="0" cellspacing="0" background="images/TYPE_BG.gif">      <tr> <td    height=26></td></tr>    </table> <br>           <table    align="center" border="1" cellspacing="0" style="border-collapse: collapse" bordercolor="#D6E6F0" cellpadding="6">              <tr><td colspan="2"    background="IMAGES/bac.gif"><div align="center"><b> 登陆信息</b></div></td> </tr> <tr>         <td width="69">用户名:</td>      <td width="124">  <input name="uname" type="text"     size="15" maxlength="15"> </td></tr> <tr>         <td>密码:</td>         <td width="124">  <input name="psw" type="password"     size="15" maxlength="15" > </td></tr><tr>              <td height="25" align="center" colspan="2" >        <input type="submit" value="确定" name="Submit" >      <input type="hidden" name="doCreate" value="true">      <input type="reset" value="取消" name="Submit2">           </td></tr>           </table>        <br></td></tr>      </table> </form>  </html>

 

原创粉丝点击