jsp+servlet实现的验证登陆
可以将业务逻辑处理和视图相分离,使用jsp界面表示视图,使用servlet处理业务逻辑

login.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
String msg=(String)request.getAttribute("msg");
if(msg!=null){
out.print(msg);
}
%>
<form action="dologin" method="post">
username:<input type="text" name="username" /><br>
password:<input type="password" name="password" /><br>
<input type="submit" value="submit" />
</form>
</body>
</html>
success.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
登陆成功
<%
String username=request.getParameter("username");
out.print(username+"欢迎你");
%>
</body>
</html>
fail.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
登陆成功
<%
String username=request.getParameter("username");
out.print(username+"欢迎你");
%>
</body>
</html>
业务逻辑处理
com.zk.myservlet.dologin.java
public class dologin extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//获取表单数据
String username=request.getParameter("username");
String password=request.getParameter("password");
//处理业务逻辑
if("Tom".equals(username)&&"123".equals(password))
{
//分发转向
request.getSession().setAttribute("username", username);
request.getRequestDispatcher("/success.jsp").forward(request, response);
//response.sendRedirect(request.getContextPath()+"/success.jsp");//丢失 username参数值 ,一次请求
}
else
{
//分发转向
//request.getRequestDispatcher("/fail.jsp").forward(request,response);
//response.sendRedirect(request.getContextPath()+"/fail.jsp");
request.setAttribute("msg", "用户名密码不正确");
request.getRequestDispatcher("/login.jsp").forward(request,response);
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request,response);
}
}
jsp+servlet实现的验证登陆的更多相关文章
- Servlet生成验证码并进行账号密码和验证码的验证登陆!
前言: 人不是生来就懂事的,在编程的世界也是一样,想想在大一的时候我还是那个连输出Hello World!都不会的小孩子是,现在我已经可以编出属于我自己的小程序了.编程其实并不可怕,可怕的是你不去编. ...
- 基于jsp+servlet图书管理系统之后台万能模板
前奏: 刚开始接触博客园写博客,就是写写平时学的基础知识,慢慢发现大神写的博客思路很清晰,知识很丰富,非常又价值,反思自己写的,顿时感觉非常low,有相当长一段时间没有分享自己的知识.于是静下心来钻研 ...
- Java web servlet 拦截器 以登陆为例子
以登陆为例子............... public class LoginFilter implements Filter { @Override public void destroy() { ...
- jsp+servlet+mysql 实现简单的银行登录转账功能
jsp+servlet+mysql 实现简单的银行登录转账功能 [前期的准备] html(登录界面),servlet(处理业务逻辑),jsp(主要实现界面),mysql(实现与数据库的简单的交互)先从 ...
- JSP/Servlet基础语法
相关学习资料 http://my.oschina.net/chape/blog/170247 http://docs.oracle.com/cd/E13222_01/wls/docs81/webapp ...
- JSP&Servlet学习手册
JSP&Servlet学习手册 沙琪玛 书 目录 JSP 指令... 3 书写方式... 3 指令列表... 3 JSP 内置对象... 3 内置对象特点... 3 常用内置对象... 3 o ...
- 基于JSP+SERVLET的新闻发布系统(一)
本系统使用的是基于JSP+SERVLET+TOMCAT6 数据库使用的是MYSQL IDE是MYECLIPSE8.5,页面编辑使用的是百度的ueditor,比较适合咱国人 采用MVC模式,使用的关键技 ...
- 基于jsp+servlet图书管理系统之后台用户信息插入操作
前奏: 刚开始接触博客园写博客,就是写写平时学的基础知识,慢慢发现大神写的博客思路很清晰,知识很丰富,非常又价值,反思自己写的,顿时感觉非常low,有相当长一段时间没有分享自己的知识.于是静下心来钻研 ...
- 软件架构设计学习总结(18):MVC三层架构在各框架(jsp+servlet + Struts1+ Struts2+ springMVC)中的特征
1.基于web开发中最原始的jsp+Servlet 图形化理解jsp+servlet结构: 1.从结构上分析jsp+servlet图解原理: 在基于mvc设计模式下的最原始的jsp+Servlet ...
随机推荐
- Selenium chromeDriver启动时报错:session not created: This version of ChromeDriver only supports Chrome
解决方案: 这是因为ChromeDriver与本地chrome浏览器的版本不一致导致 ChromeDriver下载地址:http://npm.taobao.org/mirrors/chromedriv ...
- linux执行计划任务at命令
https://www.jianshu.com/p/17f5aa01853f 在linux计划任务中, cron 是周期性运行某任务,假如我只想在未来的某时间点只是要求任务运行一次,这就用到at命令了 ...
- ActiveMQ使用JDBC持久化
步骤一:创建一个数据库 步骤二:配置activemq.xml配置文件 1.在persistenceAdapter加入如下配置 <!--crea ...
- Spring的代理模式(静态,JDK,CGLIB)
一.静态代理 1.定义业务接口 public interface Subject { void doSomeThing(); } 2.真实业务类实现接口 public class RealSu ...
- linux - mysql 异常:MySQL Daemon failed to start.
报错内容 MySQL Daemon failed to start. 如果直接输入 mysql -root -p 登陆会出现 [mysql]ERROR 2002 (HY000): Can't conn ...
- nice-validator判断表单是否验证通过
$("#formSurvery").isValid(function(is){ if(is){ alert("通过!") } } 如果is为false则表示不通 ...
- vue组件插槽与编译作用域
<!DOCTYPE html> <html> <head> <title></title> </head> <script ...
- openresty入门文章(笔者自用)
推荐好的openresty入门介绍文章:https://www.cnblogs.com/digdeep/p/4859575.html
- Paper: A novel method for forecasting time series based on fuzzy logic and visibility graph
Problem Forecasting time series. Other methods' drawback: even though existing methods (exponential ...
- Android 系统签名
在做android产品开发的时候,很多时候都需要使用系统签名(比如在使用uid,APK升级的时候),所以,android提供给我们自定义签名文件的工具.这里将流程记录下来: 1.进入/android_ ...