登陆页面源代码
来源:互联网 发布:md4算法 编辑:程序博客网 时间:2024/04/29 06:09
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, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(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 class="style1">登陆</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>
- 登陆页面源代码
- 网页设计~登陆页面源代码
- 登陆页面
- 登陆页面
- 登陆页面
- 登陆页面
- 登陆页面
- 安卓中QQ登陆源代码
- 自动化登陆百度页面的登陆页面
- 自动登陆FTS源代码管理
- 判断用户登陆 页面
- moss自定义登陆页面
- QeePHP:后台登陆页面
- extjs登陆系统页面
- moss自定义登陆页面
- 登陆页面增加javascript
- 防止登陆页面嵌套
- 退回到登陆页面
- 转帖一篇博客园的学习贴~
- 浅谈JSP与数据库的交互
- Android良好的权限设计——给想要在后台做点手脚的开发者或者公司
- Ubuntu设置分辨率
- 验证码生成器(四位)
- 登陆页面源代码
- JAVA 心得
- 求In (x)导数的欧拉方法
- Twitter名人
- HIVE RCFile高效存储结构
- Eclipse中乱码问题
- rowid的使用
- 代码精进 更新中...
- cstring.IsEmpty