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>

jsp第5个作业的更多相关文章

  1. JSP第十一次作业

    1.第十二周上机作业(邮件功能)的控制层代码改用为servlet实现.2.学习通发布了考试,截止到本周六.  com.gd.dao  BaseDao 1 package com.gd.dao; 2 3 ...

  2. jsp内置对象作业3-application用户注册

    1,注册页面 zhuCe.jsp <%@ page language="java" contentType="text/html; charset=UTF-8&qu ...

  3. jsp内置对象作业2-留言簿

    1.留言簿页面:liuYan.jsp <%@ page language="java" contentType="text/html; charset=UTF-8& ...

  4. jsp内置对象作业1-用户登录

    题目:编写一个jsp程序,实现用户登录,当用户输入的用户名或密码错误时,将页面重定向到错误提示也,并在该页面显示30秒后,自动返回到用户登录页面. 1.用户登录页面 <%@ page langu ...

  5. jsp第七周作业

    1.p78-p79的例4-9 <%@ page language="java" import="java.util.*" pageEncoding=&qu ...

  6. jsp第六次作业

    1. <%@ page language="java" import="java.util.*" pageEncoding="utf-8&quo ...

  7. jsp第三次作业

    1.在jsp页面中使用include动态标记加载音频 <%@ page language="java" import="java.util.*" page ...

  8. JSP第八次作业

    数据库test 中建个表 stu(stuid 主键 自动增长 ,用户名,密码,年龄) 1.设计一个注册页面,实现用户注册功能2.设计一个登陆页面,实现用户名密码登陆3.两个页面可以互相超链接 1 pa ...

  9. JSP第七次作业

    1.做一个图书类Book id,name,price ,get,set访问器,构造方法2个,1个无参,1个有参做一个测试类,在main中创建3个图书对象,放到list集合中.做一个菜单,可以添加,删除 ...

  10. JSP第五次作业

    1.教材P78-79  例4-9 1 <%@ page language="java" import="java.util.*" pageEncoding ...

随机推荐

  1. 修复右键批量打印PDF文件的功能

    bat文件内容如下, 直接右键管理员运行即可. @echo off rem "功能描述:修复右键批量打印PDF文件的功能" rem "制作人:赵龙" rem & ...

  2. 图片上传造成VS关闭

    原来的地方:https://q.cnblogs.com/q/129719/ VS2019开启调试,测试图片上传的时候,一点到图片上传,直接导致VS调试崩掉,返回 程序"[14764] iis ...

  3. mysql在windows下安装

    参考博客:https://blog.csdn.net/weixin_43423484/article/details/124408565

  4. 使用supervisor 管理 laravel 框架中的进程

    前言:在laravel中,经常要在项目根目录下执行 php artisan queue:work  来执行队列中的任务,由此,我们想到用supervisor来管理这个进程 Supervisor是用Py ...

  5. 封装python代码,避免被轻易反编译

    可使用Cython对python代码进行封装,封装成.pyd库,大致流程可参考: cython打包py成pyd,pyinstaller打包uvicorn服务过程记录_Bolly_He的博客-CSDN博 ...

  6. surfaceview+mediaplayer

    public class VideosurfaceView extends SurfaceView implements SurfaceHolder.Callback, MediaPlayer.OnP ...

  7. ctfshow CRYPTO RSA系列

    ctfshow CRYPTO RSA系列 目录 ctfshow CRYPTO RSA系列 babyRSA 分析 解题 esayrsa1 分析 解题 esayrsa2 分析 解题 esayrsa3 分析 ...

  8. C语言printf输出32位十六进制

    long c = 0X1DAB83; //十六进制数字 printf("c=%lx\n", c); //以十六进制形式输出(字母小写) printf("c=%lX\n&q ...

  9. python中时间的相互转换

    import time import datetime 三种常用时间形式 # 时间戳 timer = time.time() # 格式化的字符串时间 struct_time = time.strfti ...

  10. DDD(三)DDD实战、贫血模型与充血模型

    DDD(三)DDD实战.贫血模型与充血模型 如果觉得样式不好:跳转即可 http://www.lifengying.site/(md文件复制过来有些样式会不一样) 贫血模型与充血模型 1.贫血模型:一 ...