Removing / faces / from url in JSF applications

I created a site using JSF 2.0

All links are listed below.

http://www.mywebsite.com/faces/index.xhtml

I want to remove / faces /, so that the final URL will be as below.

http://www.mywebsite.com/index.xhtml

Note. I want to achieve this by passing parameters.

This question is related to my previous question.

I tried to change filter criteria for my new filter

<filter>
    <filter-name>UrlRewrite</filter-name>
    <filter-class>com.lab.filter.UrlRewriteFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>UrlRewrite</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

WITH

<filter>
    <filter-name>UrlRewrite</filter-name>
    <filter-class>com.lab.filter.UrlRewriteFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>UrlRewrite</filter-name>
    <url-pattern>/</url-pattern> // here made change from /* to /
</filter-mapping>

But that made mistakes. The webpage is not displayed.

What I want to achieve from the previous one is mywebsite.com/faces/dr.rajesh to mywebsite.com/dr.rajesh


Full WEB-INF as shown below.

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Production</param-value>
    </context-param>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>faces/index.xhtml</welcome-file>
    </welcome-file-list>
    <filter>
        <filter-name>restrict</filter-name>
        <filter-class>com.lab.filter.MyFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>restrict</filter-name>
        <url-pattern>*.xhtml</url-pattern>
    </filter-mapping>
    <filter>
        <filter-name>MyFacesExtensionsFilter</filter-name>
        <filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>MyFacesExtensionsFilter</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
    </filter-mapping>
    <context-param>
        <param-name>primefaces.THEME</param-name>
        <param-value>none</param-value>
    </context-param>
    <context-param>
        <param-name>com.sun.faces.enableRestoreView11Compatibility</param-name>
        <param-value>true</param-value>
    </context-param>

    <filter>
        <filter-name>UrlRewrite</filter-name>
        <filter-class>com.lab.filter.UrlRewriteFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>UrlRewrite</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>
+4
source share
1 answer

In your web.xml you can add url template as follows:

<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
+9
source

Source: https://habr.com/ru/post/1568480/


All Articles