Servlet案例三
来源:互联网 发布:卖男装的淘宝店铺 编辑:程序博客网 时间:2024/06/15 23:33
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登陆成功提示页面</title>
</head>
<body>
登陆成功。<br/>
您提交的信息为:<br/>
用户名:<%= request.getParameter("uname") %><br/>
密码:<%= request.getParameter("upwd") %><br/>
<a href="login.jsp">返回登陆页面</a>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登陆议程提示页面</title>
</head>
<body>
登陆失败。<br/>
您提交的信息为:<br/>
用户名:<%= request.getParameter("uname") %><br/>
密码:<%= request.getParameter("upwd") %><br/>
<a href="login.jsp">返回登陆页面</a>
</body>
</html>
修改LoginServlet.java中的doPost方法
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.println("======进入doPost方法======");
String userName = req.getParameter("uname");
String password = req.getParameter("upwd");
System.out.println("用户名 ==》 " + userName);
System.out.println("密码 ==》 " + password);
if (userName.equals("darkmi") && password.equals("jikexueyuan")) {
resp.sendRedirect(req.getContextPath() + "/14/success.jsp");//sendRedirect页面的重定向,无法获取之前提交的表单数据
} else {
resp.sendRedirect(req.getContextPath() + "/14/error.jsp");
}
}
web.xml文件不变
重启Tomcat 打开浏览器http://local
当输入用户名为darkmi并且密码为jikexueyuan 跳转到 http://local
登陆成功。
您提交的信息为:
用户名:null
密码:null
返回登陆页面
否则跳转到http://local
打开FireFox浏览器http://local
响应头Location字段 "/JSPStudy/14/success.jsp"
- Servlet案例三
- servlet应用 配置案例
- servlet 登陆注销案例
- 案例:Servlet处理表单
- servlet应用案例
- Servlet 基础案例
- Servlet案例二
- Servlet案例四
- Servlet案例五
- Servlet案例六
- Servlet与数据库连接案例
- Servlet代码案例
- Servlet监听器案例
- 【服务器+手机端项目】Android+Servlet+JSON综合案例之Android结合serlvet【三】
- servlet学习之servlet入门案例
- Servlet过滤器案例-自动登录
- Jsp+servlet 验证码案例
- 有关servlet的小案例
- 虫洞
- Linux常用命令
- 直通BAT面试算法---智力题2-赛马
- 写一个程序,定义抽象基类Shape,由它派生出3个派生类: Circle(圆形)、Rectangle(矩形)、Triangle(三角形)
- zy的秘密(secret)
- Servlet案例三
- SQL 之 视图(一)
- 资源勘探 纪中1282 vijos 1663 枚举+分类讨论
- 【codevs 1643】线段覆盖 3
- 数据库增删改操作(DML)
- Ubuntu 安装Eclipse
- UVA 147 Dollars 完全背包
- [CUDA学习]1.CUDA了解及入门
- java基础——强软弱虚引用