第六周jsp
2021-05-30 20:03
标签:map uid username 验证 red encoding gets EDA contex 1.数据库连接 2.数据库操作登录 3.servlet(密码或用户名错误返回页面并提示) 4.若不存在,跳到登录页面 第六周jsp 标签:map uid username 验证 red encoding gets EDA contex 原文地址:https://www.cnblogs.com/zrz1/p/14655579.html 1 package util;
2
3 import com.alibaba.druid.pool.DruidDataSourceFactory;
4
5 import javax.sql.DataSource;
6 import java.io.IOException;
7 import java.io.InputStream;
8 import java.sql.Connection;
9 import java.sql.SQLException;
10 import java.util.Properties;
11
12 public class JDBCUtil {
13 private static DataSource ds;
14 static {
15 Properties pro=new Properties();
16 InputStream is = JDBCUtil.class.getClassLoader().getResourceAsStream("druid.properties");
17 try {
18 pro.load(is);
19 ds = DruidDataSourceFactory.createDataSource(pro);
20 } catch (IOException e) {
21 e.printStackTrace();
22 } catch (Exception e) {
23 e.printStackTrace();
24 }
25
26 }
27 public static DataSource getDataSource(){return ds;}
28 public static Connection getConnection() throws SQLException {
29 Connection connection=ds.getConnection();
30 return connection;
31 }
32 }
public Doctor Login(Doctor loginDoctor) {
try {
String sql="select * from doctors where username = ? and password = ?";
Doctor doctor = temp.queryForObject(sql, new BeanPropertyRowMapper
package web.Servlet;
import domain.Doctor;
import org.apache.commons.beanutils.BeanUtils;
import service.DoctorService;
import service.impl.DoctorServiceImpl;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;
@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
String checkCode = request.getParameter("checkCode");
HttpSession session = request.getSession();
String checkcode = (String) session.getAttribute("CHECKCODE_SERVER");
if (!checkcode.equalsIgnoreCase(checkCode)){
request.setAttribute("error_msg","验证码错误");
request.getRequestDispatcher("/index.jsp").forward(request,response);
return;
}
Map
上一篇:Echarts——Invalid geoJson format Cannot read property 'length' of undefined
下一篇:jQuery ajax简单用法