login.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>一二零叁的网站</title>
<script type="text/javascript">
function zhuce(){
alert("跳转到注册界面......");
}
</script>
</head>
<body>
<center>
<h1 style="color:#7D26CD">登录</h1>
<hr style="width:85%">
<form id="indexform" name="indexForm" action="logincheck.jsp"
method="post">
<table border="0">
<tr>
<td>账号:</td>
<td colspan="2"><input type="text" name="username">
</td>
</tr>
<tr>
<td>密码:</td>
<td colspan="2"><input type="password" name="password">
</td>
</tr>
<tr>
<td colspan="3" align="center">
<br>
<input type="submit" value="登录" style="color:#BC8F8F">
<input type="button" onclick="zhuce()" value="注册" style="color:#BC8F8F">
</td>
</tr>
</table>
</form>
</center>
</body>
</html>
logincheck.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
request.setCharacterEncoding("UTF-8");
String username = (String) request.getParameter("username");
String password = (String) request.getParameter("password");//取出login.jsp的值
if ("88".equals(username)) {
if (!"88".equals(password)) {
out.print("<script language='javaScript'> alert('密码错误');</script>");
response.setHeader("refresh", "0;url=login.jsp");
} else {
response.sendRedirect("../resource/handsontable/demo/index.html");
}
} else {
out.print("<script language='javaScript'> alert('用户名错误');</script>");
response.setHeader("refresh", "0;url=login.jsp");
}
%>
结果:
原文地址:https://www.cnblogs.com/GodSince/p/11233596.html
时间: 2024-10-31 04:07:27