package controller;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
public class LoginServlet extends HttpServlet {
/**
* Constructor of the object.
*/
public LoginServlet() {
super();
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String username = request.getParameter("username").trim();
String password = request.getParameter("password").trim();
String resource = "mybatis-config.xml";
InputStream inputStream = Resources.getResourceAsStream(resource);
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder()
.build(inputStream);
SqlSession session=sqlSessionFactory.openSession();
Map<String,Object> params = new HashMap<>();
params.put("username", username);
params.put("password", password);
List<User> us = session.selectList("getPassword",username);
User user = us.get(0);
if(user.getPassword().equals(password)){
request.getRequestDispatcher("/index.jsp").forward(request,response);
}
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print(this.getClass());
out.println(", using the POST method");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
}
辣椒种子
- 粉丝: 4294
- 资源: 5837
最新资源
- 基于Hough变换和区间算术确定MRI序列图像中肺部运动的研究
- jsp+ssm房屋租赁管理系统
- 泥沙自动震动过滤网设备sw17可编辑全套技术资料100%好用.zip
- 基于PCA算法的脑肿瘤T1加权MRI图像聚类分割研究与比较
- 南瓜种子分选振动机(step+exb+说明书)全套技术资料100%好用.zip
- 木材削片机step全套技术资料100%好用.zip
- 学生与图书管理系统|Java|JSP|web网站|增删改查
- 基于博弈论的自动多目标聚类方法研究及其应用
- 校园快递物流系统|SSM|JSP
- 基于期望最大化与分水岭变换的脑部MRI图像分割方法
- EV电动汽车VCU HIL BMS HIL硬件在环仿真 文件包括: 1 新能源电动汽车整车建模说明书, 2 HIL模型包含驾驶员模块,仪表模块,BCU整车控制器模块,MCU电机模块,TCU变速箱模块
- 基于Saprk开发实现的电商平台用户行为分析系统源码+文档说明.zip
- 基于Simulink自动化建模的MBD模型管理工具 鉴于Simulink和TargetLink均提供了自动化处理脚本命令,采用MATLAB编写脚本实现一系列关于软件模型搭建的冗余、耗时且容易出错的工
- comsol 锂枝晶加流动耦合电势场,浓度场生长过程中添加流场,改变枝晶形貌
- 无刷直流电机的MRAS模型参考自适应控制算法,仿真模型 a). 当直流无刷电机的转动惯量由1.23*10-3kg.m2变为3.23*10-3kg.m和5.23*10-3kg.m时,双闭环控制和自适应控
- 毕业论文设计 MATLAB 实现基于POA-CNN-BiLSTM鹈鹕算法优化卷积双向长短期记忆神经网络进行多输入单输出回归预测模型应用于产品质量控制与优化的详细项目实例(含完整的程序,GUI设计和代码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈