If子句多条件jsp

If子句多条件jsp,jsp,session,if-statement,Jsp,Session,If Statement,我对多重条件的if子句有问题 这是代码 <% if(session.getAttribute("userid")!=null && session.getAttribute("type")=="admin"){ %> 这是会话的set属性 if (resultset.next()) { String type = resultset.getString("type"); session.setAttribute("userid",n);

我对多重条件的if子句有问题

这是代码

<% if(session.getAttribute("userid")!=null && session.getAttribute("type")=="admin"){ %>

这是会话的set属性

if (resultset.next()) {
    String type = resultset.getString("type");
    session.setAttribute("userid",n);
    session.setAttribute("type", type);
    response.sendRedirect("company.jsp");
} else {
    out.println("Invalid password <a href='index.jsp'>try again</a>");
}
if(resultset.next()){
字符串类型=resultset.getString(“类型”);
session.setAttribute(“userid”,n);
session.setAttribute(“类型”,type);
sendRedirect(“company.jsp”);
}否则{
out.println(“无效密码”);
}
它不起作用。如何修复它?


<% if(session.getAttribute("userid")!=null && session.getAttribute("type")=="admin"){ %>
第二个比较是错误的,
getAttribute()
返回一个
对象,而不是
String
。将其转换为
String
进行比较。也不要使用
=
进行
String
比较,而是使用
eqauls()



第二个比较是错误的,
getAttribute()
返回一个
对象,而不是
String
。将其转换为
String
进行比较。也不要使用
=
进行
String
比较,而是使用
eqauls()
试试这个。session.getAttribute()返回字符串值。因此使用.equals()


/*做一些手术*/

试试这个。session.getattribute()返回一个字符串值。所以使用.equals()


/*做一些手术*/

您能解释一下吗?company.jsp中的if子句吗?您想用if子句做什么?您能解释一下if子句是否在company.jsp中吗?您想用if子句检查什么?这是当userid不为null且级别(type)时的登录系统==管理员可以转到company.jsp吗?您可以详细解释一下吗?company.jsp中的if子句吗?您想用if子句做什么?您可以解释一下if子句在company.jsp中吗?您想用if子句检查什么?这是当userid不为null并且level(type)==管理员可以转到company.jsp时的登录系统
 <% if(session.getAttribute("userid")!=null && session.getAttribute("type").equals("admin")){ %>
 /*do some operations*/
 <%}%>