Search code examples
javaxmlapachejspstruts2

org.apache.tiles.definition.NoSuchDefinitionException


I tried add tiles in to this project. but it gives same error again and again. The error is "org.apache.tiles.definition.NoSuchDefinitionException: /login-success"

Here is my folder structure.

Here is my struts.xml

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

<struts>  
    <package name="tile_Framework" extends="tiles-default" > 
        <action name="login" class="tile_Framework.Login" method="execute">  
            <result name="success" type="tiles">/login-success</result>  
            <result name="error" type="tiles">/login-error</result>  
        </action>  
    </package>  
</struts>   

Here is my 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_0.dtd">   

<tiles-definitions> 
    <definition name="login-success" template="/layoutmanager.jsp">   
        <put-attribute name="title" value="Welcome Page"/>   
        <put-attribute name="body" value="/login-success.jsp"/>   
    </definition>  

    <definition name="login-error" template="/layoutmanager.jsp">   
        <put-attribute name="title" value="Login Error"/>   
        <put-attribute name="body" value="/login-error.jsp"/>   
    </definition>  
</tiles-definitions>

Here is web.xml

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

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">

    <welcome-file-list>  
        <welcome-file>index.jsp</welcome-file>  
    </welcome-file-list>  
    <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>  

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

    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
</web-app>

Here is my layoutmanager.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>
<title><tiles:getAsString name="title" /></title>
</head>
<body>

<%@  include file="header.jsp" %>
<tiles:insertAttribute name="body" />
<%@ include file="footer.jsp" %>

</body>
</html> 

How can I over come from this error.


Solution

  • Try changing from:

    <result name="success" type="tiles">/login-success</result> 
    

    to:

    <result name="success" type="tiles">login-success</result>