JSP中的错误:org.apache.jasper.JasperException:java.lang.NullPointerException

时间:2012-08-30 12:08:59

标签: jsp glassfish nullpointerexception

我运行我的网站(在jsp中),它会抛出此错误:

org.apache.jasper.JasperException: java.lang.NullPointerException

这是JSP文件的负责人:

    <%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<%
    String usrnameSession = null;
    usrnameSession = (String) session.getAttribute("username");
    if(usrnameSession == null){
        response.sendRedirect("welcome.jsp");
    }
%><head>blah...</head>

当我删除此块时:

<%
        String usrnameSession = null;
        usrnameSession = (String) session.getAttribute("username");
        if(usrnameSession == null){
            response.sendRedirect("welcome.jsp");
        }
    %>

这个网站运行良好。所以我认为原因是&lt; %%&gt;挡在上面。 那么为什么这个块不起作用呢? 请注意,我在Netbeans中编写这些代码,并在Glassfish服务器上运行:( 任何解决方案?

0 个答案:

没有答案