login.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<style type="text/css">
body{font-size:16px;}
</style>
<script type="text/javascript">
function mycheck(){
if(form1.userName.value==""){
alert("用户名不能为空,请输入用户名");
form1.userName.focuse();
return;
}
if(form1.password.value==""){
alert("密码不能为空,请输入密码");
form1.password.focus();
return;
}
if(form1.validationCode.value==""){
alert("验证码不能为空,请输入验证码");
form1.validationCode.focus();
return;
}
if(form1.validationCode.value!=form1.validationCode1.value){
alert("请输入正确的验证码");
form1.validationCode.focus();
return;
}
form1.submit1();
}
</script>
</head> <body>
<form action="logincheck.jsp" name="form1" method="post">
用户名:<input type="text" name="userName" size="16"><br>
密&nbsp;&nbsp;&nbsp;&nbsp;码:
<input type="password" name="password" size="18"><br>
验证码:<input type="text" name="validationCode"
onkeyDown="if(event.keyCode==13){form1.submit.focus();}" size=6>
<%
int intmethod1 = (int)(((Math.random())*11)-1);
int intmethod2 = (int)(((Math.random())*11)-1);
int intmethod3 = (int)(((Math.random())*11)-1);
int intmethod4 = (int)(((Math.random())*11)-1);
//将的到的随机数进行连接
String intsum = ""+intmethod1+intmethod2+intmethod3+intmethod4;
%>
<!--设置隐藏域验证比较时使用 -->
<input type="hidden" name="validationCode1" value="<%=intsum%>">
<input type="text" value="<%=intsum%>" size=5> <br>
<input type="submit" name="submit1" value="登录" onClick="mycheck()">
&nbsp;
<input type="reset" value="重置">
</form> <br>
</body>
</html>
logincheck.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<html>
<head>
<title>处理登录页面的数据</title>
</head>
<body bgcolor="pink">
<%
//设置请求的编码,永远解决中文乱码问题
request.setCharacterEncoding("UTF-8");
String name = request.getParameter("userName");
String password = request.getParameter("password");
if(request.getParameter("validationCode1").equals(request.getParameter("validationCode"))){
if(name.equals("chenan")&&password.equals("123456")){
session.setAttribute("userName", name);
response.sendRedirect("main.jsp"); }else{
response.sendRedirect("login.jsp"); }
}else{
response.sendRedirect("login.jsp");
}
%>
</body>
</html>
main.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<html>
<head>
<title>系统主页面</title>
</head>
<body bgcolor="pink">
<%
//获取保存在session中的用户名
String name=(String)session.getAttribute("userName");
%>
您好<%=name%>,欢迎您访问!<br>
<a href="exit.jsp">[退出系统]</a>
</body>
</html>
exit.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<html>
<head>
<title>退出系统</title>
</head>
<body>
<%
session.invalidate();//销毁session
response.sendRedirect("login.jsp");
%>
</body>
</html>

最新文章

  1. Django入门
  2. Javascript初学篇章_4(循环与函数)
  3. ecshop 获取某个商品的 所有订单信息 或者销量
  4. jQuery.mobile.activePage获取当点活动的page
  5. html textarea 获取换行
  6. Android OTA 升级之三:生成recovery.img
  7. 朴素贝叶斯算法(Naive Bayes)
  8. hdu 2993 MAX Average Problem(斜率DP入门题)
  9. HDU - 5455 Fang Fang
  10. Spring之设置Bean值
  11. day-01(html)
  12. Django 关闭Debug后使用Nginx做静态文件的访问
  13. 2018-2019-2 20165302 《网络对抗技术》Exp4 恶意代码分析
  14. 实用ExtJS教程100例-009:ExtJS Form无刷新文件上传
  15. celery_消息队列
  16. 1004 Counting Leaves (30)(30 point(s))
  17. 将代码库从 SVN 迁移至 Git 并保留所有 commit 记录
  18. recv,recvfrom,send,sendto
  19. 在linux下PHP和Mysql环境搞事情
  20. Cow Contest(最短路floyed传递闭包)

热门文章

  1. mmdetection3d安装
  2. nginx: the &quot;ssl&quot; parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf
  3. 5-6:实现多窗口之异常(AttributeError: &#39;list&#39; object has no attribute &#39;click&#39;)
  4. SpringBoot2.2.2+SpringCloud-Hoxton.SR1整合eureka/gateway
  5. vue3 生成二维码 qrcodejs2-fix
  6. VUE学习-基础(基础语法 &amp; 模板语法)
  7. 大规模人脸分类—allgather操作(1)
  8. Google Chrome 离线安装包官方下载
  9. 上传镜像到harbor
  10. maven install 报错 The POM for com.oracle:ojdbc6:jar:11.2.0.7.0 is missing, no dependency information available