今天在测试tiles框架的时候,一个报错郁闷了我好久

   

javax.servlet.ServletException: java.lang.IllegalArgumentException: Path display.add.product.form does not start with a "/" character
通常出现这个报错的主要原因是action中设置forward元素跳转时候f跳转路径值前面忘记写"/"导致,不过很明显我的确是没有以/开头,但我现在用的是tiles框架做ui啊,跳转的并不是路径值,而是
指向tiles指定的xml文件中匹配的变量名而已,所以确定应该是tiles框架的配置出现了问题,所以它认为你forward要做的是一般的路径跳转动作而已。

查了一下,struts1.3跟之前的版本比较,标签库等的导入有了很大的改变。这里参考了struts文档的说明:

Here's how to use Tiles in your own application:

  • Ensure that a struts-tiles.jar is available in the WEB-INF/lib directory of your web application.
  • Add this init-param to the Action Servlet definition in web.xml:
        <init-param>
            <param-name>chainConfig</param-name>
            <param-value>org/apache/struts/tiles/chain-config.xml</param-value>
        </init-param>
        
  • Configure the Tiles Plugin to load your definitions.
        <plug-in className="org.apache.struts.tiles.TilesPlugin">
        <set-property
            property="definitions-config"
               value="/WEB-INF/tiles-defs.xml"/>
        </plug-in>
        
  • At the top of each JSP page that will use the Tiles custom tags, add a line that declares the Tiles custom tag library.
        <%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
    文档中说明了正确配置tiles框架的步骤,我缺少的正是第一步,在xml中加上了第一步,问题解决了。
    •     

posted on 2011-05-06 21:04  KuSiuloong  阅读(1509)  评论(0编辑  收藏  举报