CheckServlet.class
package Login; import java.io.*; import java.net.*; import java.sql.ResultSet; import java.sql.sqlException; import javax.servlet.*; import javax.servlet.http.*; public class CheckServlet extends httpServlet { private static final long serialVersionUID = 1L; protected voID processRequest(httpServletRequest request,httpServletResponse response) throws servletexception,IOException { response.setContentType("text/HTML;charset=UTF-8"); String name = request.getParameter("uname"); String pword = request.getParameter("pword"); String path = request.getcontextpath(); if (login(name,pword)) { path = path + "/success.Jsp"; } else { path = path + "/index.Jsp"; } response.sendRedirect(path); } protected voID doGet(httpServletRequest request,IOException { processRequest(request,response); } protected voID doPost(httpServletRequest request,response); } public String getServletInfo() { return "Short description"; } private boolean login(String uname,String pword) { boolean flag = false; String sql = "select count(*) from d_xt_yh where yh_mc='" + uname + "' and yh_mm='" + pword + "'"; try { ResultSet rs = Dbutil.executequery(sql); while (rs.next()) { if (rs.getInt(1) > 0) flag = true; } } catch (sqlException e) { e.printstacktrace(); } catch (ClassNotFoundException e) { e.printstacktrace(); } return flag; } }
数据库连接类文件
package Login; import java.sql.*; public class Dbutil { static String driver = "com.microsoft.jdbc.sqlserver.sqlServerDriver"; static String url = "jdbc:microsoft:sqlserver://localhost:1433;Databasename=xmglxt"; static String user = "sa"; static String pwd = "sa"; public static Connection getConn() throws ClassNotFoundException,sqlException { Connection conn = null; Class.forname(driver); conn = DriverManager.getConnection(url,user,pwd); return conn; } public static ResultSet executequery(String sql) throws sqlException,ClassNotFoundException { Connection conn = Dbutil.getConn(); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executequery(sql); // Dbutil.close(conn,stmt,rs); return rs; } public static voID close(Connection conn,Statement stmt,ResultSet rs) throws sqlException { rs.close(); stmt.close(); conn.close(); } }
JsP文件
<%@page ContentType="text/HTML"%>
<%@page pageEnCoding="UTF-8"%>
<HTML>
<head>
<Meta http-equiv="Content-Type" content="text/HTML; charset=UTF-8">
<Title>登陆</Title>
</head>
<body>
<center><br><br><br>
<form action="Login/CheckServlet" method="post">
<table wIDth="259" border="1" cellpadding="0" cellspacing="0" bordercolor="#0099FF">
<tr align="center">
<td height="20" colspan="2"><span >登陆</span></td>
</tr>
<tr>
<td wIDth="50" height="20">用户名</td>
<td wIDth="161" align="left"><input name="uname" type="text" ID="uname" size="19"></td>
</tr>
<tr>
<td height="20">密码</td>
<td align="left"><input name="pword" type="password" ID="pword" size="20"></td>
</tr>
<tr align="center">
<td colspan="2"><input type="submit" name="submit" value="提交">
<input type="reset" name="submit" value="重置"></td>
</tr>
</table>
</form>
</center> </body></HTML>
总结以上是内存溢出为你收集整理的登陆页面源代码全部内容,希望文章能够帮你解决登陆页面源代码所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)