无法比较jsp中的整数对象

无法比较jsp中的整数对象,jsp,servlets,Jsp,Servlets,我无法比较“c”和“c1”,即使对象“c”的值打印1 我的代码如下:- <% Integer c1=new Integer(1); Integer c =(Integer) session.getValue("login"); // value of login is int type in servlet out.println(c); //it works correctly if(c=

我无法比较“c”和“c1”,即使对象“c”的值打印1 我的代码如下:-

         <%
          Integer c1=new Integer(1);
          Integer c =(Integer) session.getValue("login"); // value of login is int type in servlet
          out.println(c);  //it works correctly
          if(c==c1 && c!=null)   //it does not work correctly 
          {
           response.sendRedirect("homepage.jsp");
          }
          %>


请回答这个问题

如果(c==c1),是否意味着c已经等于c1,因此它不是空的????我想你应该检查一下(c!=null),然后,检查c是否等于c1这里你不必检查(c!=null)只检查(c==c1),因为c1的值为1。你能不能请你的答案解释一下为什么你的代码工作而OP的不工作?@hichris123首先,你必须检查c是否不是null。。。如果c为空,您甚至无法将其与c1进行比较。。。这很明显。。。
if(c!=null) {
    if(c==c1) {
        response.sendRedirect("homepage.jsp");
    }
}