JSP登录中Session的用法实例详解(jsp实现用户登录注册)学会了吗

随心笔谈2年前发布 编辑
170 0
🌐 经济型:买域名、轻量云服务器、用途:游戏 网站等 《腾讯云》特点:特价机便宜 适合初学者用 点我优惠购买
🚀 拓展型:买域名、轻量云服务器、用途:游戏 网站等 《阿里云》特点:中档服务器便宜 域名备案事多 点我优惠购买
🛡️ 稳定型:买域名、轻量云服务器、用途:游戏 网站等 《西部数码》 特点:比上两家略贵但是稳定性超好事也少 点我优惠购买


import java.io.IOException;
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;

@WebServlet(“/IndexServlet”)
public class IndexServlet extends HttpServlet {
private static final long serialVersionUID=1L;

public IndexServlet() {
super();
// TODO Auto-generated constructor stub
}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.getWriter().append(“Served at: “).append(request.getContextPath());
}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
request.setCharacterEncoding(“utf-8”);
String user=request.getParameter(“user”);
String password=request.getParameter(“password”);

String path=request.getContextPath();
HttpSession session=request.getSession();

if (“1”.equals(user) && “1”.equals(password)) {

session.setAttribute(“name”, user);
response.sendRedirect(path + “/success.jsp”);

}else{
response.sendRedirect(path + “/Index.jsp”);
}
}

}

© 版权声明

相关文章