org.apache.jasper.JasperException:java.lang.NullPointerException:找不到模块'null'

时间:2015-09-19 00:28:49

标签: java jsp tomcat struts-1

我正在使用Struts创建HelloWorld示例并获得异常。

的index.jsp

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>

<html:form>
Name : <html:text property="name"></html:text>
    <html:submit value="Click"></html:submit>

</html:form>

的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">
    <display-name>HelloWorld</display-name>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

    <servlet>
        <servlet-name>actionservlet</servlet-name>
        <servlet-class>org.apache.struts.actions.ActionServlet</servlet-class>
        <init-param>
            <param-name>config</param-name>
            <param-value>/WEB-INF/struts-config.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>actionservlet</servlet-name>
        <url-pattern>*.do</url-pattern>
    </servlet-mapping>

</web-app>

HelloFormBackup.java

public class HelloFormBackup extends ActionForm{
    private String name;
    public void setName(String name) {
        this.name = name;
    }
    public String getName() {
        return name;
    }

    @Override
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {

        ActionErrors ae = new ActionErrors();
        if(name.equals("")){
            ae.add("name", new ActionMessage("msg"));   
        }
        return ae;
    }
}

Messages.properties

msg=<font color='red'>  name is required.... </font>

HelloController.java

public class HelloController extends Action {

    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
            HttpServletResponse response) throws Exception {

        String name = request.getParameter("name");

        request.setAttribute("result", "hello...."+name);

        return mapping.findForward("success");
    }
}

的success.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%= request.getAttribute("result") %>

在使用Tomcat 6时获得以下异常

  org.apache.jasper.JasperException: java.lang.NullPointerException: Module 'null' not found.
        org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:502)
        org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:430)
        org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
        org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:723)


root cause 
java.lang.NullPointerException: Module 'null' not found.
    org.apache.struts.taglib.TagUtils.getModuleConfig(TagUtils.java:755)
    org.apache.struts.taglib.TagUtils.getModuleConfig(TagUtils.java:735)
    org.apache.struts.taglib.html.FormTag.lookup(FormTag.java:818)
    org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:488)
    org.apache.jsp.index_jsp._jspx_meth_html_005fform_005f0(index_jsp.java:106)
    org.apache.jsp.index_jsp._jspService(index_jsp.java:76)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:723)

在使用Tomcat 7时获得以下异常

org.apache.jasper.JasperException: An exception occurred processing JSP page /index.jsp at line 6

3: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
4: <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
5: 
6: <html:form>
7: Name : <html:text property="name"></html:text>
8:  <html:submit value="Click"></html:submit>
9: 


Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)



root cause 
java.lang.NullPointerException: Module 'null' not found.
    org.apache.struts.taglib.TagUtils.getModuleConfig(TagUtils.java:755)
    org.apache.struts.taglib.TagUtils.getModuleConfig(TagUtils.java:735)
    org.apache.struts.taglib.html.FormTag.lookup(FormTag.java:818)
    org.apache.struts.taglib.html.FormTag.doStartTag(FormTag.java:488)
    org.apache.jsp.index_jsp._jspx_meth_html_005fform_005f0(index_jsp.java:115)
    org.apache.jsp.index_jsp._jspService(index_jsp.java:85)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)

1 个答案:

答案 0 :(得分:0)

看起来jsp引擎没有找到tab lib。根据您使用的struts版本,您需要定义

<tablib-uri> 
<tablib-location>
在web.xml中

或将struts-tablib.jar正确放入项目目录中。请参阅此链接http://www.mkyong.com/struts/configure-the-struts-tag-libraries/