Style Sheet does not apply on first JSF page
The style sheet does not apply on my first JSF page. I've got a index.jsp which forwards to my first JSF page.
<html>
<head></head>
<body>
<jsp:forward page="./start.jsf" />
</body>
</html>
On start.jsf the style sheet does not apply but if I navigate to a second page my style sheet fully applies.
The second page was my first page before and I开发者_如何学编程've had the same behaviour. Without changes, the second page works fine as long as the page is not the first one in row.
Therefore CSS and the page itself must be correct. I think it's a configuration issue.
Any ideas?
You should invoke the index page using an URL which invokes the FacesServlet
. It's namely the one responsible for doing the JSF works. So you need to invoke it by index.jsf
instead of index.jsp
.
However, better is to get rid of this hacky index page altogether and define start.jsf
as <welcome-file>
in web.xml
instead.
<welcome-file-list>
<welcome-file>start.jsf</welcome-file>
</welcome-file-list>
and supply an empty start.jsf
file in the same folder next to the start.jsp
file so that the servletcontainer will be fooled that the index page really exists (it namely by default doesn't check on any servlet mappings for the index page).
Try to use redirect instead of forward. You can do this like this in your jsp:
<% response.setStatus(301);
response.setHeader("Location", "/start.jsf?" + request.getQueryString());
response.setHeader("Connection", "close");
%>
or use
response.sendRedirect("/start.jsf?" + request.getQueryString());
It is not best way to solve problem, I use in my project tuckey urlrewrite:
<urlrewrite>
...
<rule enabled="true">
<from>^/$</from>
<to last="true">/index.jsf</to>
</rule>
...
</urlrewrite>
精彩评论