基于feign传参MultipartFile问题解决
434
2022-07-22
本文实例为大家分享了java实现注册登录跳转的具体代码,供大家参考,具体内容如下
创建数据库,创建一个登录表login存储用户的用户名和密码,使用sql insert语句将注册的信息插入到数据库中,使用sql select语句查询用户名和密码是否存在数据库的login表中,实现登录功能。
依赖
注册前端页面
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
账号:
密码:
后端代码
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 java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
@WebServlet("/login")
public class LoginServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("UTF-8");
String pwd = req.getParameter("u_pwd");
String no = req.getParameter("u_no");
try {
Connection con = EmisUtils.getConnection();
String sql="insert into login(u_no,u_password)values(?,?)";
PreparedStatement ps = con.prepareStatement(sql);
ps.setString(1,no);
ps.setString(2,pwd);
ps.execute();
con.close();
ps.close();
} catch (Exception e){
e.printStackTrace();
}
req.getRequestDispatcher("enter.jsp").forward(req,resp);
}
}
登录页面前端名称 enter.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
账号:
密码:
后端页面
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 java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@WebServlet("/enter")
public class EnterServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("UTF-8");
String no = req.getParameter("u_no");
String pwd = req.getParameter("pwd")JIbyVF;
try {
Connection connection = JdbcUtils.getConnection();
String sql="select u_no,u_password From login where u_no =? and u_password=?";
PreparedStatement ps= connection.prepareStatement(sql);
ps.setString(1,no);
ps.setString(2,pwd);
ResultSet resultSet=ps.executeQuery();
if(resultSet.next())
{
System.out.println("登录成功");
}else {
System.out.println("用户名或密码错误");
}
} catch (Exception e){
e.printStackTrace();
}
}
}
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~