0

So I have jsf set up on my server and it has some xhtml files that I can call using:

http://myserver.com/sms/faces/myfile.xhtml

But I also have some files with ".csv" extension, ".js" extension, some image files and some text files with ".txt" extension, and obviously some xhtml files as already mentioned, on the same directory

As I have said the above URL works, but this url does not:

http://myserver.com/sms/faces/csvfile.csv

Again, this works:

http://myserver.com/sms/faces/jsfile.js

So I see that it is able to serve xhtml, js, images but is not able to serve csv or txt files. Is there some configuration that is not letting the JSF to serve these kinds of file.

Just a little background: The reason I need this is because I am trying to load some csv files using jquery's get method but that method is not able to find my csv files. If I change the extension of those files to js or xhtml or html, jquery loads those resources and my programs work fine. But I dont like changing the extension. I would like jsf to serve my csv files as they are.

Rash
  • 7,677
  • 1
  • 53
  • 74

1 Answers1

1

CSV files are not JSF files. You should thus make sure that the request URL on CSV files don't match the <url-pattern> of the FacesServlet instance as configured in your web.xml. This way they will be served by servletcontainer's default servlet as they are supposed to.

Another point is that /faces/* path mapping is a leftover from the dark JSF 1.0 ages. During that era, it was not possible to just map the FacesServlet on exactly the extension of view files. It would run in an infinite loop calling itself everytime. But since JSF 2.0 it's fortunately possible.

So, your best bet would be reconfiguring your FacesServlet instance like that:

<servlet-mapping>
    <servlet-name>facesServlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

This way you get rid of /faces/* virtual path altogether and you never need to deal with virtual URLs anymore.

If that's not an option for some unclear reason, then you'll just need to change the CSV URL in jQuery side to say ../csvfile.csv instead of csvfile.csv.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555