`
xiatiaohcx
  • 浏览: 32557 次
  • 性别: Icon_minigender_1
  • 来自: 山西
社区版块
存档分类
最新评论

java面试——写一个web登录界面

阅读更多

给某营业系统写一个登陆界面。

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" 
	xmlns="http://java.sun.com/xml/ns/j2ee" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
	http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  <welcome-file-list>
    <welcome-file>Login.html</welcome-file>
  </welcome-file-list>
</web-app>

 

 

Login.html

<html>
    <head>
       <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    </head>
	<body>
		<form id="form1" name="form1" method="post" action="index.jsp">
			用户名:
			<input type="text" name="userName" />
			密码:
			<input type="password" name="Password" />
			<input type="submit" name="Submit" value="登陆" />
		</form>
	</body>
</html>

 

index.jsp

<%@page contentType="text/html;charset=GBK"%>
<%@page import="java.sql.*"%>
<html>
	<body>
		<%
			String userName = request.getParameter("userName");
			String Password = request.getParameter("Password");
			if (userName == null || Password == null || userName.equals("")
					|| Password.equals("")) {
				out.print("<script type='text/javascript'>alert('输入不全');location.href('Login.html');</script>"); 
				return;
			}
			String sqls = "select * from users where username='" + userName
					+ "' and USERPWD='" + Password + "'";
			try {
				Class.forName("oracle.jdbc.driver.OracleDriver");
				Connection conn = DriverManager.getConnection(
						"jdbc:oracle:thin:@172.16.10.193:1521:sxqx", "sxqx",
						"sxqx");
				Statement stmt = conn.createStatement();
				ResultSet rs = stmt.executeQuery(sqls);
				if (rs.next()) {
					out.println("欢迎进入本页");
				} else {
					out.println("<script>alert('用户名密码不匹配');location.href('Login.html');</script>");
				}
				rs.close();
				stmt.close();
				conn.close();
			} catch (Exception e) {
				e.printStackTrace();
			}
		%>
	</body>
</html>

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics