正确显示引入和使用Struts标签库的JSP页面

如果JSP文件引入struts标签库,并且采用struts标签来显示表单,有两个地方必须做出修改,否则显示JSP页面要报错。

 

1、修改web.xml文件

 

<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>*.action</url-pattern>

</filter-mapping>

      

<filter-mapping>

    <filter-name>struts2</filter-name>

    <url-pattern>*.jsp</url-pattern>

</filter-mapping> 

 

增加一个过滤器映射(加粗部分),这样就能够过滤JSP文件。

 

如果没有增加该过滤映射,运行引入了struts标签库的JSP页面,会报如下错误。

The Struts dispatcher cannot be found.  This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location]

      

2、采用<s: form>标签,action属性值中的".action"必须删除掉。

posted on 2017-11-25 15:35  3r3r3www  阅读(420)  评论(0编辑  收藏  举报

导航