struts2tiles

Calling ActionClass in tiles.xml using Struts 2.0


I reviewed the example of tiles with struts2.0 and found that in tiles.xml jsp pages are called like:

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

BUT my question is if I want to call the action class instead of .jsp pages than how to call it like

<definition name="friends" extends="baseLayout">
  <put-attribute name="title"  value="Friends"/>
  <put-attribute name="body"   value="/checkActionLink.action"/>      

when I am trying to write to execute the above code than its showing the error that checkActionLink.action is not found....thanks in advance for the help.....

Following is the web.xml file

<?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>Struts2Example15</display-name>
    <servlet>
        <servlet-name>tiles</servlet-name>
        <servlet-class>org.apache.tiles.web.startup.TilesServlet</servlet-class>
        <init-param>
            <param-name>org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</param-name>
            <param-value>/WEB-INF/tiles.xml</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
    </servlet>
    <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>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>INCLUDE</dispatcher>
    </filter-mapping>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>

Solution

  • After so much research I found out that adding the following tag: <dispatcher>FORWARD</dispatcher> in the web.xml the issue gets resolved.

    Now the question arises why? As per my understanding when we add any action as the value of value attribute of the <put-attribute/> tag the request is forwarded to the mentioned action so the action is executed successfully.

    Previously <dispatcher>FORWARD</dispatcher> tag was missing so this issue was caused.

    I would really appreciate if any correction is there in my understanding.

    Thanks. Happy Coding :).