我想让我的URL更适合SEO。

我配置了过滤器,它可以与以下示例一起使用:

<url-mapping>
    <pattern value="/index" />
    <view-id value="/index.html" />
</url-mapping>


但是,当我将view-id设置为某些Struts URL时,它不起作用。

例如。:

<url-mapping>
    <pattern value="/index" />
    <view-id value="/application/PunchIt.do" />
</url-mapping>


它找不到(或无法执行)Struts动作。

是否有任何解决方案可与Struts 2框架一起配置PrettyFaces?

我正在使用漂亮的面孔3.3.3。

这是pretty-config.xml的配置:

<?xml version="1.0" encoding="UTF-8"?>
<pretty-config xmlns="http://ocpsoft.org/prettyfaces/3.3.3"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://ocpsoft.org/prettyfaces/
               http://ocpsoft.org/xml/ns/prettyfaces/ocpsoft-pretty-faces-3.3.3.xsd">

    <!-- doesn't work -->
    <url-mapping>
        <pattern value="/index.html" />
        <view-id value="/application/PunchIt.do" />
    </url-mapping>

    <!-- works -->
    <url-mapping>
        <pattern value="/error" />
        <view-id value="/error.html" />
    </url-mapping>
 </pretty-config>


这是web.xml:

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

  <display-name>Struts Blank</display-name>

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

  <filter>
    <filter-name>Pretty Filter</filter-name>
    <filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class>
  </filter>

  <filter-mapping>
    <filter-name>Pretty Filter</filter-name>
    <url-pattern>/* </url-pattern>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>ERROR</dispatcher>
  </filter-mapping>

</web-app>

最佳答案

您必须确保PrettyFilter位于Struts2过滤器之前,并且Struts2过滤器被配置为处理FORWARD调度程序类型。所以尝试这样的事情:

<filter>
  <filter-name>Pretty Filter</filter-name>
  <filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class>
</filter>
<filter-mapping>
  <filter-name>Pretty Filter</filter-name>
  <url-pattern>/*</url-pattern>
  <dispatcher>FORWARD</dispatcher>
  <dispatcher>REQUEST</dispatcher>
  <dispatcher>ERROR</dispatcher>
</filter-mapping>

<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>FORWARD</dispatcher>
  <dispatcher>REQUEST</dispatcher>
</filter-mapping>


有关详细说明,请参见此处的问题2:

http://www.ocpsoft.org/docs/prettyfaces/3.3.3/en-US/html/FAQ.html

08-16 04:33