sendRedirect()不能按预期工作

醉爸爸

我有这个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.jspifusertype等于,student然后重定向到facultyhome.jspif usertypeequals faculty),但是当usertypeis时null,我只想继续加载页面,而不是出现以下错误。我在这里做错了什么

Masudul

当usertype为null时,我只想继续加载页面而不是得到错误。

你会得到NullPointerException,如果usertypenull你可以简单地通过互换忽略这个错误的位置usertypeequals的方法if-else条件

if("student".equals(usertype)){
    response.sendRedirect("studenthome.jsp");
}
else if("faculty".equals(usertype)){
    response.sendRedirect("facultyhome.jsp");
}    

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

:not()不能按预期工作

来自分类Dev

:not()不能按预期工作

来自分类Dev

AutoResizeTextView不能按预期工作

来自分类Dev

getElementById不能按预期工作?

来自分类Dev

递归IEnumerable不能按预期工作?

来自分类Dev

jQuery slideDown不能按预期工作

来自分类Dev

递归函数不能按预期工作

来自分类Dev

Javascript RegExp'*'不能按预期工作

来自分类Dev

strtoul()不能按预期工作?

来自分类Dev

$ nin与$ elemMatch不能按预期工作

来自分类Dev

终于不能按预期工作

来自分类Dev

whenAll()不能按预期工作

来自分类Dev

arraylist不能按预期工作

来自分类Dev

QGridLayout不能按预期工作

来自分类Dev

unset()不能按预期工作

来自分类Dev

onclick不能按预期工作

来自分类Dev

bcrypt nodejs不能按预期工作

来自分类Dev

NavigationManager不能按预期工作?

来自分类Dev

bcrypt nodejs不能按预期工作

来自分类Dev

getElementById不能按预期工作?

来自分类Dev

rsync不能按预期工作

来自分类Dev

jQuery has()不能按预期工作

来自分类Dev

blockUI不能按预期工作

来自分类Dev

seekg()不能按预期工作

来自分类Dev

XmiCasDeserializer不能按预期工作

来自分类Dev

ArrayAdapter不能按预期工作

来自分类Dev

$(“#form”)。submit(); 不能按预期工作

来自分类Dev

fork()不能按预期工作

来自分类Dev

jQuery slideDown不能按预期工作