views:

706

answers:

1

I started to integrate struts 2 with tiles on IntelliJ environment.

I searched several tutorial on the web, but I still see some wierd symbol not found issue.

This is the web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
   http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
     version="2.5">

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

<context-param>
    <param-name>tilesDefinitions</param-name>
    <param-value>/WEB-INF/tiles.xml</param-value>
</context-param>
<listener>
    <listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
</listener>
</web-app>

This is 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"&gt;

<tiles-definitions>

  <definition name="baseLayout" template="/baseLayout.jsp">
      <put-attribute name="title"  value="Template"/>
      <put-attribute name="header" value="/header.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="welcome" extends="baseLayout">
      <put-attribute name="title"  value="Welcome"/>
      <put-attribute name="body"   value="/welcome.jsp"/>
  </definition>

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

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

</tiles-definitions>

Both tiles and web.xml under WEB-INF directory.

This is struts.xml under src directory:

<?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"&gt;

<struts>
    <package name="FirstWebApp" extends="struts-default">
        <result-types> <result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult"/> </result-types> 
        <action name="*Link" method="{1}" class="hello.HelloWorld">

            <result type="tiles" name="welcome">welcome</result>
            <result type="tiles" name="friends">friends</result>
            <result type="tiles" name="office">office</result>
        </action>
    </package>
</struts>

I am getting four errors, I think they below to two different groups:

  1. Error:(12, 13) Cannot resolve symbol 'welcome'
  2. Error:(13, 13) Cannot resolve symbol 'friends'
  3. Error:(8, 42) Cannot resolve package 'struts-default'
  4. Error:(14, 13) Cannot resolve symbol 'office'

For error 3, if I add struts-default.xml from internet, I saw a bunch of other class not found error related to com.opensymphony.xwork2 package.

For error 1, 2, and 4, I don't know how to let struts.xml to look at the tiles.xml to solve the symbol.

Thanks in advance for help.

A: 

Remove name="welcome" name="friends" name="office" and use "tiles-default" instead of "struts-default"

Miclinihin

related questions