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

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();
		}
	}


	
	


枫夜流萤
浏览 1250回答 1
1回答

cxxyjsj

字符串相等使用equals,不要用 ==
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java