数据库得出字符串和jsp表单传递的字符串相同,equals()函数不能匹配
从数据库中根据帐号得到的密码 和从jsp表单中提交的密码 在console中打印出来 是相同的 ,但为什么if语句中的password.equals(password1)不能执行呢,如果把if参数换成true,if语句快中就可以执行,这是为什么?
下面是servlet代码:
public class checkServlet extends HttpServlet {
	public void doPost(HttpServletRequest request,HttpServletResponse response) throws 
ServletException,
IOException
	{
  
    GuestDao guestDao=new GuestDao();
    String password1=(String)request.getParameter("password");
    String account=(String)request.getParameter("account");
    
    System.out.println("传入密码值为: "+password1);
    try {
    	String password=guestDao.checkGuest(account);        //checkGuest()返回的是从数据库查询的字符串
        System.out.println("根据帐号获取密码值为: "+password);
    	if(password.equals(password1))
    	{
       		        System.out.println("密码匹配成功");  //console中没有输出
    	//		ServletContext application=this.getServletContext();
    	//		RequestDispatcher rd= application.getRequestDispatcher("/mainPage.jsp");
    	//		rd.forward(request, response);
    	}
 	    } catch (Exception e) {
		e.printStackTrace();
	    }
 
	}
	public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
	{
		this.doPost(request, response);
	}
}
              
------解决方案--------------------看看有么有空格在字符串首尾,每个字符串调用.trim函数试试
------解决方案--------------------仔细确认下
看看有没有空格之类的