The FacesServlet cannot have a url-pattern of /*

Splash Forums PrettyFaces Users The FacesServlet cannot have a url-pattern of /*

This topic contains 9 replies, has 5 voices, and was last updated by  domdorn 6 years, 8 months ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #17852

    Last
    Participant

    Hello,

    I want to map my JSF to /*:

    <servlet-mapping>

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

    <url-pattern>/*</url-pattern>

    </servlet-mapping>

    The homepage is displayed OK, but when I go to some link (defined by <pretty:link>), I receive the error from the subject.

    If I try the URL pattern /faces/*, the homepage is still displayed OK, but links defined via <pretty:link> tag are just non clickable plain text and it seems the mapped URLActions in beans are never called.

    Thanks.

    #20614

    Why do you want to map the FacesServlet to /*. That is very uncommon. If you are using PrettyFaces you don’t have to do so to get pretty URLs. I don’t think that the error you are seeing is cause by PrettyFaces.

    Regarding the non-clickable PrettyFaces links. Could you take a look what is rendered to the HTML page. Perhaps you forgot to declare the pretty prefix in your Facelets page?

    #20615

    If you are still having troubles – you could post some of your Facelet source code, and your pretty-config.xml. We will do our best to help :)

    #20616

    Last
    Participant

    Hello,

    sorry, this was my mistake. This error appears when I access an URL I don’t have defined in the matching patterns.

    How can I map URLs of my application from the root of the domain and without mapping FacesServlet to /*? Thanks.

    #20617

    Last
    Participant

    I have problems to map any resources with this kind of errors. If I keep the pattern to /*, from this source code in index.xhtml:

    <h:head>
    <title>Facelet Title</title>
    <h:outputStylesheet library="css" name="reset.css"/>
    <h:outputStylesheet library="css" name="screen.css"/>
    </h:head>

    I get this:

    <head>
    <title>Facelet Title</title>
    <link type="text/css" rel="stylesheet" href="/gowalla-war/*/javax.faces.resource/reset.css?ln=css" />
    <link type="text/css" rel="stylesheet" href="/gowalla-war/*/javax.faces.resource/screen.css?ln=css" />
    </head>

    (notice the /*/ part in the path). If I access that URL, I get that error from the thread subject (The FacesServlet cannot have a url-pattern of /*).

    How should my web.xml look? It looks like this now:

    <?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>Development</param-value>
    </context-param>
    <context-param>
    <param-name>com.ocpsoft.pretty.BASE_PACKAGES</param-name>
    <param-value>cz.cvut.x33eja.gowalla,com.ocpsoft</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>/*</url-pattern>
    </servlet-mapping>
    </web-app>

    If I try to change the url-pattern to, for example, /faces/* and hit the Run button in netbeans, the source code is not parsed at all – I get the HTML with all the <h:…> tags in the browser.

    I really don’t what the pattern should be set to, even after reading the documentation.

    Thanks.

    #20618

    Last
    Participant

    Sorry, for the spamming, but I am facing really weird behaviour.

    If I set the pattern to /faces/* and go to http://localhost:8080/gowalla-war/, I get an unparsed code of index.xhtml. If I go to http://localhost:8080/gowalla-war/faces, I get GlassFish 404. If I go to http://localhost:8080/gowalla-war/faces/ (additional slash), I get an unparsed code again. If I go to http://localhost:8080/gowalla-war/faces/index.xhtml, I finally get what I want – parsed code with successfully loaded resources.

    But I really can’t force users to type this address and to reveal my source codes if the URL is not typed correctly, so please, tell me, what am I doing wrong :) Thanks.

    #20619

    EugeneV
    Participant

    Add this at the end of your web.xml:

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

    Nothing to do with PrettyFaces, though.

    #20620

    Last
    Participant

    That didn’t help, behaviour of all problems I described above is the same.

    #20621

    As I said before mapping the FacesServlet to /* is really not a good idea because it can cause all kinds of trouble.

    How can I map URLs of my application from the root of the domain and without mapping FacesServlet to /*? Thanks.

    If I understand you correctly you want to remove the context path of your application from the URLs? How to do this depends on the container you are using. In Tomcat for example you have to rename the WAR archive to ROOT.war before you deploy it. In this case there will be no context path in your URL.

    #20622

    domdorn
    Participant

    I usually map the Faces Servlet to

    *.xhtml

    and set the welcome-file to

    index.xhtml

    That way, I simply put a index.xhtml in the root of my web

    application have / mapped to the faces file I created.

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

You must be logged in to reply to this topic.

Comments are closed.