为了账号安全,请及时绑定邮箱和手机立即绑定

ty == "user"和ty == "administrator"都判断错误

ty == "user"和ty == "administrator"都判断错误

枫夜流萤 2017-12-26 19:40:40
package Servlet; import java.io.IOException; import java.io.PrintWriter; import java.sql.SQLException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.swing.JOptionPane; import Bean.login; import Dao.loginDao; public class loginServlet extends HttpServlet { private static final long serialVersionUID = 1L; public loginServlet() { super(); } public void destroy() { super.destroy(); } public void init() throws ServletException { } public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { return; } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String user = request.getParameter("user"); String password = request.getParameter("password"); String type = request.getParameter("type"); System.out.println("ls2"); System.out.println(type);         System.out.println(user); response.setContentType("text/html; charset=gb2312"); PrintWriter out = response.getWriter(); try{ //login lg = new Bean.login(); System.out.println("ls2"); login lg = new loginDao().login(user,type); if(lg != null|"".equals(lg)){ System.out.println("ls3"); if(lg.getPassword().equals(password)){ out.print(user); out.print(password); out.print(type); String ty = type; if(ty == "user"){ response.sendRedirect("/Bus/index.jsp"); }else if(ty == "administrator"){ response.sendRedirect("/Bus/administrator.jsp"); } }else{ JOptionPane.showMessageDialog(null, "密码错误,请重新输入密码!"); response.sendRedirect("/Bus/login.jsp"); } }else{ JOptionPane.showMessageDialog(null, "用户名不存在!"); request.getRequestDispatcher("/login.jsp").forward(request, response); } }catch(SQLException e){ e.printStackTrace(); } }
查看完整描述

1 回答

已采纳
?
cxxyjsj

TA贡献119条经验 获得超22个赞

字符串相等使用equals,不要用 ==

查看完整回答
反对 回复 2017-12-26
  • 1 回答
  • 0 关注
  • 1249 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信