当前位置: 代码迷 >> 综合 >> Jsp+Servlet+C3P0+MD5+MySQL登录验证
  详细解决方案

Jsp+Servlet+C3P0+MD5+MySQL登录验证

热度:47   发布时间:2023-10-12 01:28:07.0

简单介绍一下业务实现流程:
Jsp+Servlet+C3P0+MD5+MySQL登录验证
2.框架结构:
Jsp+Servlet+C3P0+MD5+MySQL登录验证 Jsp+Servlet+C3P0+MD5+MySQL登录验证
Jsp+Servlet+C3P0+MD5+MySQL登录验证Jsp+Servlet+C3P0+MD5+MySQL登录验证
前期工作

1.导入数据库连接相关的jar包,在这次项目中我使用的是mysql数据库所以需导入的是MySQL数据库连接驱动包(mysql-connector-java-5.1.40.jar)和c3p0连接池专属包(mchange-commons-java-0.2.11.jar、c3p0-0.9.5.2.jar)

2.编写C3P0配置文件,连接数据库,引入MySQL数据库连接驱动包和c3p0连接池专属包(mysql-connector-java-5.1.40.jar、mchange-commons-java-0.2.11.jar、c3p0-0.9.5.2.jar)

C3p0-config.xml文件这里有两种写法:

<!-- 第一种c3p0的写法 -->
<?xml version="1.0" encoding="UTF-8"?>
<c3p0-config><default-config><!-- 前四个最重要 --><!-- 设置常用的属性  url 驱动  用户 密码   --><property name="jdbcUrl"><![CDATA[jdbc:mysql://localhost:3306/water?useUnicode=true&characterEncoding=UTF8&useSSL=false]]></property><property name="driverClass">com.mysql.jdbc.Driver</property><property name="user">root</property><property name="password"></property><!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 2 --><property name="acquireIncrement">2</property><!-- 初始化数据库连接池时连接的数量 --><property name="initialPoolSize">3</property><!-- 数据库连接池中的最小的数据库连接数 --><property name="minPoolSize">3</property><!-- 数据库连接池中的最大的数据库连接数 --><property name="maxPoolSize">5</property></default-config>
</c3p0-config>
<!-- 第二种c3p0的写法 -->
<?xml version="1.0" encoding="UTF-8"?>
<c3p0-config><default-config><!-- 必填 --><!-- 驱动类 --><property name="driverClass">com.mysql.jdbc.Driver</property><!-- URL --><property name="jdbcUrl">jdbc:mysql://localhost:3306/water?useUnicode=true&amp;characterEncoding=UTF8&amp;useSSL=false</property><!-- 账号 --><property name="user">root</property><!-- 密码 --><property name="password"></property><!-- 可选 --><!-- 初始连接数 --><property name="initialPoolSize">30</property><!-- 最大闲置时间 --><property name="maxIdleTime">30</property><!-- 最大连接数 --><property name="maxPoolSize">100</property><!-- 最小连接数 --><property name="minPoolSize">20</property><!-- 最大SQL语句数 --><property name="maxStatements">200</property></default-config>
</c3p0-config>

3.测试数据库连接
编写log4j日志记录器配置文件打印日志,引入Log4j日志记录包(log4j-1.2.8.jar)
在这里我使用了Log4j日志记录器来输入变量,需要导入log4j相关的jar包(log4j-1.2.8.jar)和配置相关的配置文件(log4j.properties)

#log4j.properties
#设置日志级别和目的地
#log4j.rootCategory=日志级别,目的地1,目的地2...
#日志级别有(从低到高)OFF、FATAL、ERROR、WARN、INFO、DEBUG、ALL
#高级别的日志可以包含低级别的日志
#目的地可以定义多个log4j.rootCategory=INFO,console,file#配置目的地
#配置目的地的类型Appender
#log4j.appender.目的地名=目的地类型
#目的地类型有:
#org.apache.log4j.ConsoleAppender(控制台),
#org.apache.log4j.DailyRollingFileAppender(每天产生一个日志文件),log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %l [%p] -- %m%n#配置日志的格式Layout
#log4j.appender.目的地名.layout=格式类型
#格式类型有:
#org.apache.log4j.PatternLayout(可以灵活地指定布局模式)#配置具体的格式ConversionPattern
#%d 输出日志时间点的日期或时间,默认格式为ISO8601,也可以在其后指定格式,
#比如:%d{yyyy-MM-dd HH:mm:ss,SSS},输出类似:2002-10-18 22:10:28,921;
#%l 输出日志事件的发生位置,及在代码中的行数;
#%p 输出优先级,即DEBUG,INFO,WARN,ERROR,FATAL;
#%M 输出打印该条日志的方法名;
#%n 输出一个回车换行符,Windows平台为"rn”,Unix平台为"n”;log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %l [%p] -- %m%n
log4j.appender.file.File=mylog.log

成功连接数据库显示如下:Jsp+Servlet+C3P0+MD5+MySQL登录验证
正式开始

编写执行sql语句的配置文件(water.xml)解析XML文件,加载SQL语句到缓存

<!-- water.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<services><sql key="getAccountCount" value="select count(1) from account where user_name=? and user_pwd=?" /><sql key="findUser" value="select count(1) from account where user_name=?" />
</services>

建立工具层(utils)
Jsp+Servlet+C3P0+MD5+MySQL登录验证
1.建立解析执行sql的XML文件的解析类(WaterXmlUtils.java),引入Dom4jXML解析包(dom4j-1.6.jar、jaxen-1.1-beta-6.jar)

package com.kmyang.water.utils;import org.apache.log4j.Logger;import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;import org.dom4j.Document;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;/*** @author kmyang* @category 解析XML文件,加载SQL语句到缓存*/
public class WaterXmlUtils {/*** Logger for this class*/private static final Logger logger = Logger.getLogger(WaterXmlUtils.class);private static Document document;/**使用键值对的方式加载SQL语句到SQL_CACHE*/private static Map<String,String> SQL_CACHE= new HashMap<>();static {try {//当前线程的类加载器InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("water.xml");if (null == in) {throw new RuntimeException("配置文件加载失败");}//解析xml文件到document中SAXReader saxReader = new SAXReader();document = saxReader.read(in);initSQLCache();} catch (Exception e) {e.printStackTrace();throw new RuntimeException("配置文件初始化失败");}}/**document加载到缓存(SQLCACHE)*/private static void initSQLCache() {@SuppressWarnings("unchecked")//从xml文件中选取符合XPath运算式的节点清单List<Node> nodeList = document.selectNodes("//services//sql");//根据xml的键获得相应的值for (Node node : nodeList) {String key = node.valueOf("@key");String value = node.valueOf("@value");if (logger.isInfoEnabled()) {logger.info("key="+key+" value="+value);}SQL_CACHE.put(key, value);}}/**在water.xml中根据key获得对应得value* @param key dao对应的方法名称* @return sql语句*/public static String getSQLByKey(String key){return SQL_CACHE.get(key);}
}

2.建立c3p0连接类(C3P0Utils.java)

package com.kmyang.water.utils;import java.sql.Connection;import com.mchange.v2.c3p0.ComboPooledDataSource;/*** @author kmyang* @category c3p0连接类*/
public class C3P0Utils {/**创建ComboPooledDataSource实例*/private static ComboPooledDataSource dataSource = null;//静态初始化实例static {dataSource = new ComboPooledDataSource();}/**从dataSource实例中获取数据库连接*/public static Connection getConnection() throws Exception{return dataSource.getConnection();}
}

3.使用final关键字建立加密类(MD5Utils.java),对账号加密

package com.kmyang.water.utils;import java.math.BigInteger;
import java.security.MessageDigest;/*** @author kmyang* @category 使用MD5对账号加密*/
public final class MD5Utils {/**使用MD5对明文进行加密* 1创建一个MD5对象* 2将参数转换为UTF-8的字节数组进行加密* 3获取参数的十六进制的hashCode作为密文* @param msg* @return 明文对应的密文* @throws Exception*/public static String encoding(String msg) throws Exception{//创建加密对象MessageDigest md5 = MessageDigest.getInstance("md5");//将参数转换为UTF-8编码的字节数组,使用MD5更新明文md5.update(msg.getBytes("UTF-8"));BigInteger big  = new BigInteger(1, md5.digest());return big.toString(16);}
}

4.建立DBUtils工具类,引入DBUtils工具包(commons-dbutils-1.6.jar)使用泛型对数据进行增删改查

package com.kmyang.water.utils;import java.sql.SQLException;
import java.util.List;import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;import com.mchange.v2.c3p0.ComboPooledDataSource;/*** @author kmyang* @category 查和增删改工具类*/
public class DBUtils {/**创建一个C3p0连接池的数据源*/private static ComboPooledDataSource dataSource = new ComboPooledDataSource();/**创建执行器,将数据源注入到DBUtils*/private static QueryRunner runner = new QueryRunner(dataSource);/**返回某一个实体的所有数据信息* @param type 实体编译期类型不确定(泛型),运行期是具体类型,实体类型在内存中的class对象* @param sql 需要查询的SQL语句* @param objects select语句需要的查询参数(占位符)* @return 返回结果是一个泛型* @throws Exception*/public static <T>List<T> queryList(Class<T>type, String sql, Object ...objects ) throws Exception{return runner.query(sql, new BeanListHandler<>(type), objects);}/**返回某一个实体的单个数据信息* @param type 实体编译期类型不确定(泛型),运行期是具体类型,实体类型在内存中的class对象* @param sql 需要查询的SQL语句* @param objects select语句需要的查询参数(占位符)* @return 返回结果是一个泛型* @throws Exception*/public static <T>T queryOne(Class<T>type, String sql, Object ...objects ) throws Exception{return runner.query(sql, new BeanHandler<>(type), objects);}/**对某一个实体进行增删改* @param sql* @param objects* @return * @return* @throws Exception*/public static int update(String sql, Object ...objects) throws Exception{return runner.update(sql,objects);}
}

建立实体层(entity)
Jsp+Servlet+C3P0+MD5+MySQL登录验证
1、账号表的实体类(account.java)

package com.kmyang.water.entity;/*** @author kmyang* @category 账号表的实体*/
public class Account {/**账号*/private String userName;/**密码*/private String password;public String getUserName() {return userName;}public void setUserName(String userName) {this.userName = userName;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}@Overridepublic String toString() {return "Account [userName=" + userName + ", password=" + password + "]";}@Overridepublic int hashCode() {final int prime = 31;int result = 1;result = prime * result + ((password == null) ? 0 : password.hashCode());result = prime * result + ((userName == null) ? 0 : userName.hashCode());return result;}@Overridepublic boolean equals(Object obj) {if (this == obj)return true;if (obj == null)return false;if (getClass() != obj.getClass())return false;Account other = (Account) obj;if (password == null) {if (other.password != null)return false;} else if (!password.equals(other.password))return false;if (userName == null) {if (other.userName != null)return false;} else if (!userName.equals(other.userName))return false;return true;}public Account(String userName, String password) {super();this.userName = userName;this.password = password;}public Account() {super();}
}

建立与数据库的访问层(dao)
建立处理用户账号信息的交互类(AccountDAO.java),根据用户名和密码返回总行数进行校验
Jsp+Servlet+C3P0+MD5+MySQL登录验证

package com.kmyang.water.dao;import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;import com.kmyang.water.entity.Account;
import com.kmyang.water.utils.C3P0Utils;
import com.kmyang.water.utils.WaterXmlUtils;/*** @author kmyang* @category 处理用户账号信息*/
public class AccountDAO {/**根据账号查找账号信息* @param userName* @return* @throws Exception*/public int findUser(String userName) throws Exception{String sql = WaterXmlUtils.getSQLByKey("findUser");try(Connection conn = C3P0Utils.getConnection();PreparedStatement ps = conn.prepareStatement(sql);){ps.setString(1, userName);try(ResultSet rs = ps.executeQuery();){int result = 0;if(rs.next()){result = rs.getInt(1);}return result;}}}/**根据用户名和密码返回总行数* @param account* @return 总行数* @throws Exception*/public int getAccountCount(Account account) throws Exception{String sql = WaterXmlUtils.getSQLByKey("getAccountCount");try(Connection conn = C3P0Utils.getConnection();PreparedStatement ps = conn.prepareStatement(sql)){ps.setString(1, account.getUserName());ps.setString(2, account.getPassword());try(ResultSet rs = ps.executeQuery()){//没有匹配到用户int rows = -1;//匹配到用户信息if(rs.next()){rows = rs.getInt(1);}return rows;}}}
}

建立与数据库的传输层(dto)
Jsp+Servlet+C3P0+MD5+MySQL登录验证
建立账号数据与dao的传输类(AccountDTO.java),用于展示层与服务层之间的数据传输对象(AccountConvert.java)

package com.kmyang.water.dto;/*** @author kmyang* @category 账号数据与dao的传输类*/
public class AccountDTO {/**账号*/private String userName;/**密码*/private String password;public String getUserName() {return userName;}public void setUserName(String userName) {this.userName = userName;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}@Overridepublic String toString() {return "AccountDTO [userName=" + userName + ", password=" + password + "]";}@Overridepublic int hashCode() {final int prime = 31;int result = 1;result = prime * result + ((password == null) ? 0 : password.hashCode());result = prime * result + ((userName == null) ? 0 : userName.hashCode());return result;}@Overridepublic boolean equals(Object obj) {if (this == obj)return true;if (obj == null)return false;if (getClass() != obj.getClass())return false;AccountDTO other = (AccountDTO) obj;if (password == null) {if (other.password != null)return false;} else if (!password.equals(other.password))return false;if (userName == null) {if (other.userName != null)return false;} else if (!userName.equals(other.userName))return false;return true;}public AccountDTO(String userName, String password) {super();this.userName = userName;this.password = password;}public AccountDTO() {super();// TODO Auto-generated constructor stub}}
package com.kmyang.water.dto;import com.kmyang.water.entity.Account;/*** @author kmyang* @category 账号的entity与dto之间做数据的转换*/
public class AccountConvert {/**将dto的数据转换为实体* @param dto* @param account*/public static void dto2Account(AccountDTO dto, Account account){account.setUserName(dto.getUserName());account.setPassword(dto.getPassword());}
}

建立处理数据库的业务逻辑层(business)
1.1建立需实现的账号功能接口类(IAccountBusiness.java)
1.2查找账号名是否存在
1.3对密码的明文加密,产生密文
1.4建立实现其接口的实现类(AccountBusiness.java
Jsp+Servlet+C3P0+MD5+MySQL登录验证

package com.kmyang.water.business;import com.kmyang.water.dto.AccountDTO;
import com.kmyang.water.entity.Account;/*** @author kmyang* @category 账号接口类*/
public interface IAccountBusiness {/**查找用户名是否存在* @param userName 浏览器输入的用户名* @return true存在	false不存在* @throws Exception*/public boolean findUser(String userName) throws Exception;/**entity对密码的明文加密,产生密文* @param account* @return 条件为true有匹配的用户名* @throws Exception*/public boolean check(Account account) throws Exception;/**dto对密码的明文加密,产生密文* @param dto* @return 条件为true有匹配的用户名* @throws Exception*/public boolean check(AccountDTO dto) throws Exception;
}
package com.kmyang.water.business;import com.kmyang.water.dao.AccountDAO;
import com.kmyang.water.dto.AccountConvert;
import com.kmyang.water.dto.AccountDTO;
import com.kmyang.water.entity.Account;
import com.kmyang.water.utils.MD5Utils;/*** @author kmyang* @category 账号接口实现类*/
public class AccountBusiness implements IAccountBusiness {private 	AccountDAO dao = new AccountDAO(); @Overridepublic boolean findUser(String userName) throws Exception {return dao.findUser(userName) > 0?true : false;}@Overridepublic boolean check(Account account) throws Exception {String pwd = MD5Utils.encoding(account.getPassword());account.setPassword(pwd);return dao.getAccountCount(account) > 0?true:false;}@Overridepublic boolean check(AccountDTO dto) throws Exception {String pwd = MD5Utils.encoding(dto.getPassword());dto.setPassword(pwd);Account account = new Account();AccountConvert.dto2Account(dto, account);return dao.getAccountCount(account) > 0?true:false;}}

建立功能测试层(test)
Jsp+Servlet+C3P0+MD5+MySQL登录验证
首先测试C3P0连接池和MD5是否配置成功,然后开展后续

package com.kmyang.water.test;import org.apache.log4j.Logger;
import org.junit.Test;import java.sql.Connection;
import java.sql.SQLException;import com.mchange.v2.c3p0.ComboPooledDataSource;/*** @author kmyang* @category 测试数据库连接*/
public class TestC3P0 {/*** Logger for this class*/private static final Logger logger = Logger.getLogger(TestC3P0.class);@Testpublic void testC3P0(){ComboPooledDataSource dataSource = new ComboPooledDataSource();try {Connection conn = dataSource.getConnection();if (logger.isInfoEnabled()) {logger.info("testC3P0() - Connection conn=" + conn); }} catch (SQLException e) {e.printStackTrace();}}
}
package com.kmyang.water.test;import java.util.UUID;import org.apache.log4j.Logger;
import org.junit.Test;import com.kmyang.water.utils.MD5Utils;/*** @author kmyang* @category 测试加密功能*/
public class TestMD5 {/*** Logger for this class*/private static final Logger logger = Logger.getLogger(TestMD5.class);/**测试加密功能*/@Testpublic void testMD5(){try {
//			String result = MD5Utils.encoding("加密123abc");String result = MD5Utils.encoding("123456");if (logger.isInfoEnabled()) {logger.info("testMD5() - String result=" + result);}} catch (Exception e) {e.printStackTrace();}}/**测试获得网络资源的后缀*/@Testpublic void testStuff(){String urlPath = "http://pic1.win4000.com/pic/8/68/c926457091.jpg";int index = urlPath.lastIndexOf(".");//网络资源的后缀String stuff = urlPath.substring(index);if (logger.isInfoEnabled()) {logger.info("testStuff() - String stuff=" + stuff); }}/**测试  通用唯一标识符(Universally Unique Identifier)* uuidgen 实用程序使用网络地址信息和系统时间生成的。* 基于 uuid 的键本质上就是一个随机的、有确定格式的十六进制字符串,* 这个格式仅仅是为了确保键的唯一性。*/@Testpublic void testUUID(){UUID uuid = UUID.randomUUID();String result = uuid.toString();if (logger.isInfoEnabled()) {logger.info("testUUID() - String result=" + result);}}/**测试获得临时文件夹得系统属性*/@Testpublic void testPath(){String tmpPath = System.getProperty("java.io.tmpdir");if (logger.isInfoEnabled()) {logger.info("testPath() - String tmpPath=" + tmpPath); //$NON-NLS-1$}}
}

测试工作
1、测试账号功能是否可以正常运转(TestAccountBusiness)
1.1创建Business对象
1.2初始化Business对象
1.3开始测试相关功能点
2.1.1根据账号确认其用户是否存在`

package com.kmyang.water.test;import org.apache.log4j.Logger;import org.junit.Before;
import org.junit.Test;import com.kmyang.water.business.AccountBusiness;
import com.kmyang.water.entity.Account;/*** @author kmyang* @category 测试账号相关功能*/
public class TestAccountBusiness {/*** Logger for this class*/private static final Logger logger = Logger.getLogger(TestAccountBusiness.class);private AccountBusiness accountBusiness;@Beforepublic void setup(){accountBusiness = new AccountBusiness();}/**根据账号确认其用户是否存在*/@Testpublic void testFindUser(){String userName = "Sam";try {boolean result = accountBusiness.findUser(userName);if (logger.isInfoEnabled()) {logger.info("testFindUser() - boolean result=" + result);}} catch (Exception e) {e.printStackTrace();}}@Testpublic void testCheck(){String user = "Sam";String pwd = "1234563";Account account = new Account(user, pwd);try {boolean result = accountBusiness.check(account);if (logger.isInfoEnabled()) {logger.info("testCheck() - boolean result=" + result);}} catch (Exception e) {e.printStackTrace();}}
}

2.1.1根据账号确认其用户是否存在
Jsp+Servlet+C3P0+MD5+MySQL登录验证
1.2.1输入字符串测试MD5加密是否可以正常使用
Jsp+Servlet+C3P0+MD5+MySQL登录验证
建立前端jsp和相应的servlet
Jsp+Servlet+C3P0+MD5+MySQL登录验证
login.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>襄阳襄城送水厂之登录界面</title>
</head>
<body><form action="account.do?m=login" method="post" >用户名<input type="text" name="txtUserName" /><br/>密码<input type="password" name="txtPwd"/><br/><input type="submit" name="submit" value="提交"/><input type="reset" name="reset" value="重置"/></form>
</body>
</html>

success.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>成功success</title></head>
<body>成功success
</body>
</html>

failed.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>失败failed</title></head>
<body>失败failed
</body>
</html>

Jsp+Servlet+C3P0+MD5+MySQL登录验证

package com.kmyang.water.action;import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.Method;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;/*** @author kmyang* @category 通过反射机制实现功能*/
public class BaseServlet extends HttpServlet {/*** Logger for this class*/private static final Logger logger = Logger.getLogger(BaseServlet.class);@Overrideprotected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//		设置编码req.setCharacterEncoding("UTF-8");resp.setContentType("text/html;charset=UTF-8");PrintWriter pw = resp.getWriter();//获取m参数     m=modifyCustString reqMethod = req.getParameter("m");if (logger.isInfoEnabled()) {logger.info(req.getServletPath()+"?m="+ reqMethod+"\tstart"); }//查询的m参数为空,返回失败页面if(StringUtils.isEmpty(reqMethod)){pw.print("操作失败<a href='failed.jsp'>返回首页</a>");}try {Method method = this.getClass().getDeclaredMethod(reqMethod, HttpServletRequest.class,HttpServletResponse.class);method.invoke(this, req,resp);} catch (Exception e) {logger.error("BaseServlet",e);e.printStackTrace();}if (logger.isInfoEnabled()) {logger.info(req.getServletPath()+"?m="+ reqMethod+"\tend"); }}@Overrideprotected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {doGet(req, resp);}
}
package com.kmyang.water.action;import java.io.IOException;
import java.io.PrintWriter;import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import com.kmyang.water.business.AccountBusiness;
import com.kmyang.water.dto.AccountDTO;/*** @author kmyang* @category 登录功能*/
@WebServlet(urlPatterns="/account.do")
public class AccountServlet extends BaseServlet {private AccountBusiness biz = new AccountBusiness();public void login(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {PrintWriter pw = resp.getWriter();String userName = req.getParameter("txtUserName");String pwd = req.getParameter("txtPwd");try {//条件成立,跳转到成功界面if(biz.check(new AccountDTO(userName, pwd))){req.getRequestDispatcher("water/success.jsp").forward(req, resp);}else{req.getRequestDispatcher("water/failed.jsp").forward(req, resp);}} catch (Exception e) {e.printStackTrace();}}
}
  相关解决方案