how to write rewrite rule?

Splash Forums PrettyFaces Users how to write rewrite rule?

This topic contains 4 replies, has 2 voices, and was last updated by  dolphincn 5 years, 8 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #18137

    dolphincn
    Participant

    I still confused after read the document of pretty-faces.

    if my website is http://www.dolphin.com/

    and I want to use the link http://www.dolphin.com/admin

    to access the webpage http://www.dolphin.com/web/admin/admin.xhtml(that actully page web address in server).

    so if i key in “http://www.dolphin.com/admin” in IE address, the IE can display the webpage http://www.dolphin.com/web/admin/admin.xhtml.

    how to write the rewrite rule in pretty-config.

    #22001
    <url-mapping>
    <pattern value="/admin" />
    <view-id value="/admin/admin.xhtml" />
    </url-mapping>

    Note that .xhtml in the above mapping should be changed to whatever extension your Faces Servlet is mapped to. If you don’t use extensions, then you’ll need to add the correct URL prefix to match your Faces Servlet mapping.

    Hope this helps,

    Lincoln

    #22002

    dolphincn
    Participant

    I used netbeans 7.1 and tomcate 7 and mojarra jsf 2.1.

    I have difined the rule like you desciption. but something set wrong at web.xml about jsf configuration that cause following error.

    type Exception report

    message

    description The server encountered an internal error () that prevented it from fulfilling this request.

    exception

    com.sun.faces.context.FacesFileNotFoundException: /admin/index.xhtml Not Found in ExternalContext as a Resource

    com.sun.faces.facelets.impl.DefaultFaceletFactory.resolveURL(DefaultFaceletFactory.java:232)

    com.sun.faces.facelets.impl.DefaultFaceletFactory.resolveURL(DefaultFaceletFactory.java:273)

    com.sun.faces.facelets.impl.DefaultFaceletFactory.getMetadataFacelet(DefaultFaceletFactory.java:209)

    com.sun.faces.application.view.ViewMetadataImpl.createMetadataView(ViewMetadataImpl.java:114)

    com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:233)

    com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)

    com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:116)

    com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)

    javax.faces.webapp.FacesServlet.service(FacesServlet.java:409)

    org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)

    note The full stack trace of the root cause is available in the Apache Tomcat/7.0.22 logs.


    <?xml version=”1.0″ encoding=”UTF-8″?>

    <web-app xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221;

    xmlns=”http://java.sun.com/xml/ns/javaee&#8221;

    xmlns:web=”http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&#8221;

    xsi:schemaLocation=”http://java.sun.com/xml/ns/javaee

    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd

    id=”WebApp_ID” version=”2.5″>

    <display-name>JavaServerFaces</display-name>

    <!– JSF mapping –>

    <servlet>

    <servlet-name>Faces Servlet</servlet-name>

    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>

    <load-on-startup>1</load-on-startup>

    </servlet>

    <!– ================<Facelets>====================================–>

    <!– Use Documents Saved as *.xhtml –>

    <context-param>

    <param-name>javax.faces.DEFAULT_SUFFIX</param-name>

    <param-value>.xhtml</param-value>

    </context-param>

    <!– ================</Facelets>===================================–>

    <!– ======Faces Servlet Mapping ===================================–>

    <servlet-mapping>

    <servlet-name>Faces Servlet</servlet-name>

    <url-pattern>*.xhtml</url-pattern>

    </servlet-mapping>

    <welcome-file-list>

    <welcome-file>index.xhtml</welcome-file>

    </welcome-file-list>

    </web-app>


    <pretty-config xmlns=”http://ocpsoft.com/prettyfaces/3.3.2&#8243;

    xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221;

    xsi:schemaLocation=”http://ocpsoft.com/prettyfaces/3.3.2

    http://ocpsoft.com/xml/ns/prettyfaces/ocpsoft-pretty-faces-3.3.2.xsd“>

    <url-mapping>

    <pattern value=”/” />

    <view-id value=”/index.xhtml” />

    </url-mapping>

    <url-mapping>

    <pattern value=”/admin” />

    <view-id value=”/admin/admin.xhtml” />

    </url-mapping>

    </pretty-config>

    #22003

    dolphincn
    Participant

    It redirect to /admin/index.xhtml not /admin/admin.xhtml

    it seemed is tomcat redirect to the virtual host /admin.

    #22004

    dolphincn
    Participant

    at last I found it need append “/” at the end of pattern.

    <url-mapping>

    <pattern value=”/admin/” />

    <view-id value=”/admin/admin.xhtml” />

    </url-mapping>

    now it work.

    I think something configure setting wrong before, because I have tried this way.

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

You must be logged in to reply to this topic.

Comments are closed.