Reputation: 125
I want to make my URLs nicer for SEO.
I configured the filter and it works with the following e.g.:
<url-mapping>
<pattern value="/index" />
<view-id value="/index.html" />
</url-mapping>
But when I set view-id to some Struts URL it does not work.
E.g.:
<url-mapping>
<pattern value="/index" />
<view-id value="/application/PunchIt.do" />
</url-mapping>
It can not find (or can not execute) Struts actions.
Is there any solution to configure PrettyFaces together with Struts 2 framework?
I'm using pretty-faces 3.3.3.
Here is the config of 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>
Here is the 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>
Upvotes: 1
Views: 102
Reputation: 5668
You have to make sure that the PrettyFilter is located before the Struts2 filter AND that the Struts2 Filter is configured to process FORWARD dispatcher types. So try something like this:
<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>
For a detailed explanation, see question #2 here:
http://www.ocpsoft.org/docs/prettyfaces/3.3.3/en-US/html/FAQ.html
Upvotes: 2