0

I'm trying to implement a custom PDF file servlet (/fileprovider/name?param1=value&param2=otherValue) on a JSF 2 web application, but when declaring it on web.xml the application always adds .xhtml extension to every request. I believe due to the DEFAULT_SUFFIX context-param.

<!-- ... -->
<context-param>
    <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
    <param-value>.xhtml</param-value>
</context-param>
<context-param>
    <param-name>org.omnifaces.FACES_VIEWS_SCAN_PATHS</param-name>
    <param-value>/*.xhtml</param-value>
</context-param>

<servlet>
    <servlet-name>faces</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet>
    <servlet-name>MyPDFServlet</servlet-name>
    <servlet-class>com.company.servlet.MyPDFServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>MyPDFServlet</servlet-name>
    <url-pattern>/fileprovider/name</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>faces</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<!-- ... -->

The exception thrown is:

FacesFileNotFoundException: /name.xhtml Not Found in ExternalContext as a Resource

So I believe that the path is not mapped correctly, maybe I'm missing something.

Is there any way to specify that I want specific paths to point to custom servlets without adding .xhtml extension?

nuno
  • 1,771
  • 1
  • 19
  • 48
  • I'm trying to implement a servlet so that an external application (an applet) may download, alter and upload a given file. Right now I'm trying to implement the download part. I don't intend to use this in the web application itself. – nuno Oct 31 '14 at 14:56
  • Uhm... Well, I'm basically trying to access (via applet) some backend filesystem while a webbapp is up. In order to do that, I want to use a servlet in the webapp (for session validation and such) to process some parameters and respond with a file. I'm not accessing the servlet with `` nor ``. Does this make sense? Should I be using servlets at all? – nuno Oct 31 '14 at 15:17
  • Actually I followed one of your tuts [here](http://balusc.blogspot.pt/2007/07/fileservlet.html). What I'm not able to do is use the path like this: `file?id=xyz`. I have to use a dummy `file/dummy?id=xyz` if the servlet is mapped with `/file/*`. – nuno Oct 31 '14 at 15:23
  • You don't need the "dummy." Just `file/?id=xyz` would work. If you don't want the slash, you should try `/file` – developerwjk Oct 31 '14 at 22:35
  • @developerwjk If I try the `/file` url-pattern, it maps to `file.xhtml`, even though the servlet-mapping is declared first than the `*.xhtml`. – nuno Nov 03 '14 at 09:20

0 Answers0