1

我开始在 IntelliJ 环境中将 struts 2 与磁贴集成。

我在网上搜索了几个教程,但我仍然看到一些奇怪的符号未找到问题。

这是 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>

这是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="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>

WEB-INF 目录下的tiles 和web.xml。

这是src目录下的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>
    <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>

我收到四个错误,我认为它们属于两个不同的组:

  1. 错误:(12, 13) 无法解析符号“欢迎”
  2. 错误:(13, 13) 无法解析符号“朋友”
  3. 错误:(8, 42) 无法解析包“struts-default”
  4. 错误:(14, 13) 无法解析符号“办公室”

对于错误 3,如果我从 Internet 添加 struts-default.xml,我看到一堆其他类未找到与 com.opensymphony.xwork2 包相关的错误。

对于错误1、2、4,不知道怎么让struts.xml看tiles.xml来解决符号。

提前感谢您的帮助。

4

1 回答 1

1

删除 name="welcome" name="friends" name="office" 并使用 "tiles-default" 而不是 "struts-default"

于 2010-03-10T10:32:12.440 回答