我有这个Register.jsp
页面,页面加载时,我想检查用户是否已经登录。所以我有这个代码,
<%
String usertype = (String)session.getAttribute("usertype");
if(usertype.equals("student")){
response.sendRedirect("studenthome.jsp");
}
else if(usertype.equals("faculty")){
response.sendRedirect("facultyhome.jsp");
}
%>
当用户登录时它可以工作(它重定向到studenthome.jsp
ifusertype
等于,student
然后重定向到facultyhome.jsp
if usertype
equals faculty
),但是当usertype
is时null
,我只想继续加载页面,而不是出现以下错误。我在这里做错了什么
当usertype为null时,我只想继续加载页面而不是得到错误。
你会得到NullPointerException
,如果usertype
是null
。你可以简单地通过互换忽略这个错误的位置usertype
上equals
的方法if-else
条件
if("student".equals(usertype)){
response.sendRedirect("studenthome.jsp");
}
else if("faculty".equals(usertype)){
response.sendRedirect("facultyhome.jsp");
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句