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>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值