java.lang.NullPointerException org.apache.tiles.definition.UnresolvingLocaleDefinitionsFactory.getDefinition

时间:2016-11-18 11:32:10

标签: jsp configuration struts2 tiles struts2-tiles-plugin

我正在为我的项目使用struts2 + hibernate集成并在此实现了tile,但遇到了这个问题

  

struts.xml中

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
   "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
   "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
    <constant name="struts.devMode" value="true" />

    <package name="default" extends="hibernate-default">

        <result-types>
            <result-type name="tiles"
                class="org.apache.struts2.views.tiles.TilesResult" />
        </result-types>

        <action name="*Menu" method="{1}"
            class="com.struts2hibernatepagination.action.MenuAction">
            <result name="tiger" type="tiles">tiger</result>
            <result name="lion" type="tiles">lion</result>
        </action>

        <action name="addStudent" method="execute"
            class="com.struts2hibernatepagination.action.AddStudentAction">
            <interceptor-ref name="defaultStackHibernateStrutsValidation">
                <param name="validation.excludeMethods">listStudents</param>
                <param name="validation.excludeMethods">fetchStudentList</param>
            </interceptor-ref>
            <result name="success" type="redirect">
                listStudents
            </result>
            <result name="input">/student.jsp</result>
        </action>

        <action name="listStudents" method="listStudents"
            class="com.struts2hibernatepagination.action.AddStudentAction">
            <interceptor-ref name="basicStackHibernate" />
            <result name="success">/student.jsp</result>
            <result name="input">/student.jsp</result>
        </action>

        <action name="fetchStudentList"
            class="com.struts2hibernatepagination.action.AddStudentAction"
            method="listStudents">
            <interceptor-ref name="basicStackHibernate" />
            <result name="success">/displaytag.jsp</result>
            <result name="input">/student.jsp</result>
        </action>

        <action name="listStudentByName"
            class="com.struts2hibernatepagination.action.AddStudentAction"
            method="edit">
            <interceptor-ref name="basicStackHibernate" />
            <result name="success">/searchStudent.jsp</result>
            <result name="input">/searchStudent.jsp</result>
        </action>

        <action name="studentFirstNameList"
            class="com.struts2hibernatepagination.action.AddStudentAction"
            method="studentFirstName">
            <interceptor-ref name="basicStackHibernate" />
            <result name="success">/searchStudent.jsp</result>
        </action>

    </package>
</struts>
  

tiles.xml

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE tiles-definitions PUBLIC
   "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
   "http://tiles.apache.org/dtds/tiles-config_2_2.dtd">

<tiles-definitions>

    <definition name="baseLayout" template="/baseLayout.jsp">
        <put-attribute name="title" value="Template" />
        <put-attribute name="banner" value="/banner.jsp" />
        <put-attribute name="menu" value="/menu.jsp" />
        <put-attribute name="body" value="/body.jsp" />
        <put-attribute name="footer" value="/footer.jsp" />
    </definition>

    <definition name="tiger" extends="baseLayout">
        <put-attribute name="title" value="Tiger" />
        <put-attribute name="body" value="/tiger.jsp" />
    </definition>

    <definition name="lion" extends="baseLayout">
        <put-attribute name="title" value="Lion" />
        <put-attribute name="body" value="/lion.jsp" />
    </definition>

</tiles-definitions>
  

的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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    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>Struts2Example17</display-name>

    <context-param>
   <param-name>
      org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG
   </param-name>
   <param-value>
      /WEB-INF/tiles.xml
   </param-value>
   </context-param>

    <listener>
   <listener-class>
      org.apache.struts2.tiles.StrutsTilesListener
   </listener-class>
   </listener>


    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>
            org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
        </filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <welcome-file-list>
        <welcome-file>student.jsp</welcome-file>
    </welcome-file-list>
</web-app>
  

MenuAction.java

package com.struts2hibernatepagination.action;

import com.opensymphony.xwork2.ActionSupport;

public class MenuAction extends ActionSupport {

    public String tiger() {
        return "tiger";
    }

    public String lion() {
        return "lion";
    }

}
  

banner.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">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<img src="http://www.tutorialspoint.com/images/tp-logo.gif"/>
</body>
</html>
  

baseLayout.jsp

<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title><tiles:insertAttribute name="title" ignore="true" /></title>
</head>
<body>
    <tiles:insertAttribute name="banner" />
    <br />
    <hr />
    <tiles:insertAttribute name="menu" />
    <br />
    <hr />
    <tiles:insertAttribute name="body" />
    <br />
    <hr />
    <tiles:insertAttribute name="footer" />
    <br />
</body>
</html>
  

lion.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">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<img src="http://upload.wikimedia.org/wikipedia/commons/d/d2/Lion.jpg"/>
The lion
</body>
</html>
  

引入了menu.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
    <a href="<s:url action="tigerMenu"/>">Tiger</a>
    <br>
    <a href="<s:url action="lionMenu"/>">Lion</a>
    <br>
</body>
</html>
  

tiger.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">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
    <img src="http://www.freewebs.com/tigerofdarts/tiger.jpg" /> The tiger
</body>
</html>

我在项目中使用的库列表

enter image description here

在我尝试访问http://localhost:8080/Struts2HibernatePagination/tigerMenu.action

之后,这是一个快照

有人可以告诉我为什么我得到这个例外,因为我在最近2天遇到了这个问题,并且尝试了很多改变各种库但没有任何工作!!请帮助!! :(

1 个答案:

答案 0 :(得分:2)

我用

替换了库
  
      
  1. struts2-tiles-plugin-2.1.6.jar
  2.   
  3. tiles-api-2.1.2.jar
  4.   
  5. tiles-compat-2.1.2.jar
  6.   
  7. tiles-core-2.1.2.jar
  8.   
  9. tiles-jsp-2.1.2.jar
  10.   
  11. 瓦片-servlet的2.1.2.jar
  12.   

它有效!

它不适用于瓷砖2.2罐子