Mapping a servlet to a prettier url thanks to pretty faces: is that possible?

Splash Forums PrettyFaces Users Mapping a servlet to a prettier url thanks to pretty faces: is that possible?

This topic contains 13 replies, has 3 voices, and was last updated by  Lincoln Baxter III 10 years, 8 months ago.

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
  • #17923



    I have the following servlet/pattern:


    I would like for the users only to see a pattern such as:


    Is that possible with pretty faces? Can someone help with some sample code or a pointer to the relevant section in the documentation please?

    Note that in this case there’s no jsf implied.

    Thanks in advance,



    I for myself always use PrettyFaces in conjunction with JSF, so I’m not a real expert here but you should try something like this:

    <url-mapping id="confirm">
    <pattern value="/confirmationAbonne/#{abonneToken}"/>

    See this page for details:

    Or perhaps with a rewrite rule:

    <rewrite match="^/confirmationAbonne/([w-]+)$" substitute="/ConfirmationAbonneServlet?abonneToken=$1" redirect="chain"/>

    See here:

    I hope this helps




    Thanks a lot Christian!



    Sorry Christian: One last question: how do I deal with the ampersand in the substitute clause? See below:





    Here is what I tried:

    <rewrite match=”^/redirigeVersSculpture/([w-]+)$/([w-]+)$” substitute=”/RedirigeVersSculptureServlet?abonneLocale=$1#38;sculptureID=$2″ redirect=”chain”/>

    It just won’t match…

    Any idea why?




    Me again:

    I refined the match clause as follows:

    <rewrite match=”^/redirigeVersSculpture/(fr|en)/(d+)” substitute=”/RedirigeVersSculptureServlet?abonneLocale=$1#38;sculptureID=$2″ redirect=”chain”/>

    I am now getting this:


    com.ocpsoft.pretty.PrettyException: Error occurred during canonicalization of request <[/redirigeVersSculpture/fr/1]>





    cause m�re


    I use PF 3.2.1.



    In your first try the first $ character was wrong. $ means “end of line” in a regular expression.

    So it should be something like:

    <rewrite match="^/redirigeVersSculpture/([w-]+)/([w-]+)$" ... />

    Regarding the exception you are seeing. Could you perhaps post so complete stacktrace. There should be a “caused by” part below the stacktrace you have posted.



    Hello Christian,

    Here is my new config:

    <rewrite match=”^/redirigeVersSculpture/(fr|en)/(d+)$” substitute=”/RedirigeVersSculptureServlet?abonneLocale=$1&sculptureID=$2″ redirect=”chain”/>

    Here is the stacktrace:


    1 mai 2011 14:43:08 org.apache.catalina.core.StandardContext filterStart

    GRAVE: Exception au d�marrage du filtre Pretty Filter

    com.ocpsoft.pretty.PrettyException: Failed to load configuration.

    at com.ocpsoft.pretty.faces.config.PrettyConfigurator.configure(

    at com.ocpsoft.pretty.PrettyFilter.init(

    at org.apache.catalina.core.ApplicationFilterConfig.getFilter(

    at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(

    at org.apache.catalina.core.ApplicationFilterConfig.<init>(

    at org.apache.catalina.core.StandardContext.filterStart(

    at org.apache.catalina.core.StandardContext.start(

    at org.apache.catalina.core.ContainerBase.addChildInternal(

    at org.apache.catalina.core.ContainerBase.addChild(

    at org.apache.catalina.core.StandardHost.addChild(

    at org.apache.catalina.startup.HostConfig.deployDescriptor(

    at org.apache.catalina.startup.HostConfig.deployDescriptors(

    at org.apache.catalina.startup.HostConfig.deployApps(

    at org.apache.catalina.startup.HostConfig.start(

    at org.apache.catalina.startup.HostConfig.lifecycleEvent(

    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(

    at org.apache.catalina.core.ContainerBase.start(

    at org.apache.catalina.core.StandardHost.start(

    at org.apache.catalina.core.ContainerBase.start(

    at org.apache.catalina.core.StandardEngine.start(

    at org.apache.catalina.core.StandardService.start(

    at org.apache.catalina.core.StandardServer.start(

    at org.apache.catalina.startup.Catalina.start(

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(

    at java.lang.reflect.Method.invoke(

    at org.apache.catalina.startup.Bootstrap.start(

    at org.apache.catalina.startup.Bootstrap.main(

    Caused by: com.ocpsoft.pretty.PrettyException: Failed to parse PrettyFaces configuration from /WEB-INF/pretty-config.xml

    at com.ocpsoft.pretty.faces.config.spi.DefaultXMLConfigurationProvider.loadConfiguration(

    at com.ocpsoft.pretty.faces.config.PrettyConfigurator.configure(

    … 28 more

    Caused by: org.xml.sax.SAXParseException: The reference to entity “sculptureID” must end with the ‘;’ delimiter.

    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)

    at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)


    at com.ocpsoft.pretty.faces.config.DigesterPrettyConfigParser.parse(

    at com.ocpsoft.pretty.faces.config.spi.DefaultXMLConfigurationProvider.loadConfiguration(

    … 29 more

    1 mai 2011 14:43:08 org.apache.catalina.core.ApplicationContext log

    INFO: Closing Spring root WebApplicationContext

    1 mai 2011 14:43:09 org.apache.catalina.core.ApplicationContext log

    INFO: ContextListener: contextInitialized()

    1 mai 2011 14:43:09 org.apache.catalina.core.ApplicationContext log

    INFO: SessionListener: contextInitialized()


    The & character has a special meaning in XML documents. You should try to replace & with &_amp; (please remove the underscore between & and amp;, I just added it because the forum markup seems to replace this sequence with &).




    Thank a lot.

    Works very well now and is much cleaner than before thanks to PF!!



    You’re welcome! Let us know if you have any further problems! :)


    Is there a reason you opted to use rewrite instead of a url-mapping?

    It looks like what you are doing is simple enough to be done with a pattern and a few query-parameters, unless I’m reading this wrong :)




    <pattern value=/”confirmationAbonne/#{abonneToken}”>

    <view-id value=”/ConfirmationAbonneServlet”>


    That should do what you initially requested, for example.


    Sorry, I see now christian posted the same solution.

Viewing 14 posts - 1 through 14 (of 14 total)

The forum ‘PrettyFaces Users’ is closed to new topics and replies.

Comments are closed.