0

I am following this guide: http://balusc.blogspot.com/2009/12/uploading-files-with-jsf-20-and-servlet.html and everything has gone smoothly except that I noticed it would only work if my web.xml is mapped to .jsf. Any ideas?

I am on tomcat 7.0.12 jsf 2.1.17 from mojarra and that is why I'm not using Tomahawk.

edhedges
  • 2,722
  • 2
  • 28
  • 61
  • Is it possible for you too upgrade your jsf 2.1.17 to 2.2.x? In 2.2.x you have build in jsf tag which allow you to upload files `` ? – Michał Kupisiński Feb 01 '13 at 16:16
  • Not at the moment we are on Mojarra and it hasn't gotten to that stage. – edhedges Feb 01 '13 at 16:18
  • Tomahawk is not a replacement to Mojarra by the way, but just a component library which can be used on top of Mojarra. About halfway 2010, half a year after the writing of the blog you found, Tomahawk has a JSF 2.0 compatible file upload component. See also e.g. http://stackoverflow.com/a/5424229/157882 – BalusC Feb 01 '13 at 16:20
  • @BalusC Which Tomahawk is compatible with JSF 2.1.17 Mojarra? I looked on their site and I can't find the page again, but it said it may not be compatible with my installation. – edhedges Feb 01 '13 at 16:29

1 Answers1

1

You need to make sure that the URL pattern of the filter mapping of the file upload filter also matches the desired JSF requests. Assuming that your FacesServlet has a <url-pattern>*.html</url-pattern>, then this should do:

@WebFilter(urlPatterns={"*.html"})

Even better, if you're going to use it exclusively for file uploads via JSF, then you can also map it on the servlet name of the faces servlet. Assuming that you've a <servlet-name>facesServlet</servlet-name>, then this should do:

@WebFilter(servletNames={"facesServlet"})
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I'm using your code and I'm having trouble finding what I need to modify. Is it in `MultipartFilter.java`? – edhedges Feb 01 '13 at 16:21
  • I updated the answer. The example in the blog has already `/*` set by the way. I'd imagine that you've modified that, otherwise you wouldn't have this problem. Note that I also assume that this filter is not mapped in `web.xml`, otherwise the `@WebFilter` would be overridden and you'd need to modify the mapping in `web.xml` instead. – BalusC Feb 01 '13 at 16:22
  • Yeah I guess this was the wrong question to ask because what is happening is that the upload gets to a certain percentage and then just stalls. – edhedges Feb 01 '13 at 16:32
  • In other words, if you open the page by `some.jsf`, then it works fine, but when you remap it on `*.html` and open by `some.html`, then it stalls halfway? In which browser(s) have you obseved this? – BalusC Feb 01 '13 at 16:34
  • I have done everything the same as your tutorial up until http://balusc.blogspot.com/2009/12/uploading-files-with-jsf-20-and-servlet.html#ValidateUploadedFile. It stalls on all of my browsers chrome, nightly, and ie. – edhedges Feb 01 '13 at 16:44
  • I just copied all the code from the 3 year old articles into a new blank playground project with Mojarra 2.1.17 (on `*.xhtml`) and Tomcat 7.0.27. Works fine. I've only to do 2 more things apart from copying the code: 1) set `allowCasualMultipartParsing="true"` in Tomcat's `server.xml` (as warned in top of [this article](http://balusc.blogspot.com/2009/12/uploading-files-in-servlet-30.html) and 2) create `/upload` folder (I got otherwise a nice error page with `java.io.IOException: The system cannot find the path specified`). Did you set `allowCasualMultipartParsing="true"`? – BalusC Feb 01 '13 at 17:08
  • Will try this thanks. I hadn't set allowCasualMultipartParsing="true" and am no tomcat 7.0.12, but I doubt that should make a difference (the tomcat version as long as it is above 7.0.6 like you say). – edhedges Feb 01 '13 at 17:17
  • It won't work in 7.0.0-7.0.6 in any way. You need to have minimum 7.0.7 and even then, you need to set that context attribute. I admit that the warning message heading is somewhat confusing. I have now edited it and removed the version information form the heading. Note that when you're running Tomcat in Eclipse, you should be editing the `context.xml` file in Eclipse's *Servers* project instead. – BalusC Feb 01 '13 at 17:21
  • You're welcome :) It's however strange that you mentioned that it worked when using `*.jsf` (that should not have worked either at all). Isn't that just wrong observation? – BalusC Feb 01 '13 at 17:29
  • Yes I think I stated above that I must have asked the wrong question. It was an incorrect assumption on my part thinking it was because of that. – edhedges Feb 01 '13 at 17:30