gpt4 book ai didi

java - PrettyFaces 不适用于 Struts 2

转载 作者:行者123 更新时间:2023-11-30 03:27:39 25 4
gpt4 key购买 nike

我想让我的网址更适合 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 操作。

有没有办法将PrettyFaces与Struts 2框架一起配置?

我使用的是 beautiful-faces 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

关于java - PrettyFaces 不适用于 Struts 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29802878/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com