1

I have 2 pages: page1.xhtml, page2.xhtml. From page1 I go to page2. In page2 I have:

<h:commandButton value="shuffle" action="#{bean.shuffle}" immediate="true"></h:commandButton> 

When I put page in WEB-INF and clicking on shuffle I get error:

    HTTP Status 404 - 

--------------------------------------------------------------------------------

type Status report

message 

description The requested resource () is not available.


--------------------------------------------------------------------------------

Apache Tomcat/7.0.14

But when I put page2 just in WebContent, everything works good. My web.xml :

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

Why ?

Aram Gevorgyan
  • 2,175
  • 7
  • 37
  • 57
  • It is hard to tell if you don't show the code of your `bean.shuffle()` method, or at least which is its output. – SJuan76 Dec 16 '12 at 15:06
  • @SJuan76: I think, it is no matter, it outputs some string that isn't used in navigation or it may be void, same result. – Aram Gevorgyan Dec 16 '12 at 15:10
  • @SJuan76: The problem is that when page is in WEB-INF I get this error – Aram Gevorgyan Dec 16 '12 at 15:12
  • What do you mean "some string that isn't used in navigation". The result of the bean will be used in navigation, either if it is explicit or implicit. – SJuan76 Dec 16 '12 at 15:12
  • Files in WEB-INF directory are never accessible through the browser. WEB-INF if for classes/resources that will be used for processing, never downloaded. – SJuan76 Dec 16 '12 at 15:14
  • @SJuan76 I know that classes in WEB-INF are not directly accessible through the browser. "some string that isn't used in navigation" I mean that I have no navigation rule for that string – Aram Gevorgyan Dec 16 '12 at 15:17
  • @SJuan76: It return string "shuffle" or also may be void. Same result. – Aram Gevorgyan Dec 16 '12 at 15:18
  • If it is implicit navigation (not specified in `faces-config.xml`) make it return "page2.xhtml" – SJuan76 Dec 16 '12 at 15:32
  • @SJuan76: I make what you say, but it doesn't work. And when the page isn't in WEB-INF it works for any result string. – Aram Gevorgyan Dec 16 '12 at 15:36
  • 1
    @AramGevorgyan your question seems to be similar to http://stackoverflow.com/questions/9031811/which-xhtml-files-do-i-need-to-put-in-web-inf-and-which-not – Wen Ping Dec 16 '12 at 17:03
  • @WenPing No it isn't similar. I don't ask when I must put page in WEB-INF. I ask why I get error when page is in WEB-INF. Please read attentively my question, the aren't similiar. – Aram Gevorgyan Dec 16 '12 at 17:07
  • @AramGevorgyan have you read the answer to that question? – Wen Ping Dec 16 '12 at 17:10
  • @WenPing Yes I read. But when I navigate from page1 to page2 , it works normally and I get error after clicking on the comandButton. But whatever, thanks for the link. – Aram Gevorgyan Dec 16 '12 at 17:18

1 Answers1

2

Resources in /WEB-INF are not publicly accessible. You need to put publicly accessible resources outside /WEB-INF. The /WEB-INF should only be used for configuration files, template files, include files, tag files, etc which are supposed to not be publicly accessible at all.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • But what if I don't want my page be public accessible. If I don't want my page be accessible through typing directly page url in the borwser, I want page only can be navigated from my button. As I know WEB-INF is for that purposes, at least in JSP. – Aram Gevorgyan Dec 17 '12 at 15:20
  • And why I don't get error when navigating on the page, and only get error after clicking commandButon in that page. – Aram Gevorgyan Dec 17 '12 at 15:21
  • 1
    That's not true for JSP either. You're probably mixing it up with servlets. I.e. you actually invoke the servlet by URL which in turn loads (forwards) the JSP for presentation. If you want to display a JSF page on postback only, then you should conditionally render it, or to check if the request is a postback. – BalusC Dec 17 '12 at 15:24
  • I do not understand your second comment. Do you understand the difference between navigating on the page (a GET request) and submitting a form (a POST request)? – BalusC Dec 17 '12 at 15:24