Primefaces在呈现时将.xhtml扩展添加到css和.js文件中,因此样式和JavaScript不起作用
我尝试使用PrimeFaces4.0和Spring3.2.5创建一个webApp,用于依赖注入 Primefaces依赖项:Primefaces在呈现时将.xhtml扩展添加到css和.js文件中,因此样式和JavaScript不起作用,css,web-applications,jsf-2,primefaces,Css,Web Applications,Jsf 2,Primefaces,我尝试使用PrimeFaces4.0和Spring3.2.5创建一个webApp,用于依赖注入 Primefaces依赖项: <!-- primefaces and jsf --> <dependency> <groupId>org.primefaces</groupId> <artifactId>primefaces</artifactId> <vers
<!-- primefaces and jsf -->
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>${primafaces.version}</version>
</dependency>
<dependency>
<groupId>org.primefaces.themes</groupId>
<artifactId>blitzer</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>org.primefaces.themes</groupId>
<artifactId>home</artifactId>
<version>1.0.4</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1.2</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
这是登录页面:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
<h:outputScript library="js" name="mainPageHelper.js" />
<h:outputStylesheet name="login-page.css" library="css" />
</h:head>
<h:body onload="checkErrorStatus();">
<h:form id="f" styleClass="f" name="f" method="POST">
<h:outputText styleClass="error" style="color:red; display:none; background-color: #C2DFFF">given username and/or password incorrect</h:outputText>
<h:outputText>Log in</h:outputText>
<h:panelGrid id="grid" columns="3" cellpadding="4">
<p:outputLabel value="Username:" />
<p:inputText id="username" name="j_username" required="true" requiredMessage="Username is required" size="25" style="width:120px;" />
<p:message for="username"/>
<h:outputLabel value="Password:" />
<h:inputSecret id="password" name="j_password" required="true" requiredMessage="Password is required" style="width:120px;" size="25" />
<p:message for="password"/>
<p:commandButton id="loginRedirect" value="Login" action="#{loginController.loginRedirect}" ajax="false" />
</h:panelGrid>
</h:form>
</h:body>
</html>
如您所见,我正在尝试导入我自己的样式和Javascript。可以找到这些资源,但在创建页面时,每个文件甚至primefaces javascript和css都会添加一个.xhtml扩展名,如下所示:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link type="text/css" rel="stylesheet" href="/ePIBWebApp/javax.faces.resource/theme.css.xhtml?ln=primefaces-home">
<link type="text/css" rel="stylesheet" href="/ePIBWebApp/javax.faces.resource/login- page.css.xhtml?ln=css">
<link type="text/css" rel="stylesheet" href="/ePIBWebApp/javax.faces.resource/primefaces.css.xhtml?ln=primefaces&v=4.0">
<script type="text/javascript" src="/ePIBWebApp/javax.faces.resource/jquery/jquery.js.xhtml?
ln=primefaces&v=4.0"></script>
<style type="text/css"></style>
<script type="text/javascript" src="/ePIBWebApp/javax.faces.resource/primefaces.js.xhtml?ln=primefaces&v=4.0"></script>
<script type="text/javascript" src="/ePIBWebApp/javax.faces.resource/mainPageHelper.js.xhtml?ln=js"></script>
</head>
<body onload="checkErrorStatus();">
<form id="f" name="f" method="post" action="/ePIBWebApp/pages/login.xhtml" class="f" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="f" value="f">
<span class="error" style="color:red; display:none; background-color: #C2DFFF"></span><table id="f:grid" cellpadding="4">
<tbody>
<tr>
<td><label id="f:j_idt12" class="ui-outputlabel ui-widget">Username:</label></td>
<td><input id="f:username" name="f:username" type="text" size="25" style="width:120px;" class="ui-inputfield ui-inputtext ui-widget ui-state-default ui-corner-all"><script id="f:username_s" type="text/javascript">PrimeFaces.cw('InputText','widget_f_username',{id:'f:username'});</script> </td>
<td><div id="f:j_idt13" aria-live="polite" class="ui-message"></div></td>
</tr>
<tr>
<td><label>
Password:</label></td>
<td><input id="f:password" type="password" name="f:password" value="" size="25" style="width:120px;"></td>
<td><div id="f:j_idt15" aria-live="polite" class="ui-message"></div></td>
</tr>
<tr>
<td><button id="f:loginRedirect" name="f:loginRedirect" class="ui-button ui-widget ui-state- default ui-corner-all ui-button-text-only" type="submit">
<span class="ui-button-text ui-c">Login</span></button><script id="f:loginRedirect_s" type="text/javascript">PrimeFaces.cw('CommandButton','widget_f_loginRedirect', {id:'f:loginRedirect'});</script></td>
</tr>
</tbody>
</table>
<input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="4305835440482722754:-5118499173786020406" autocomplete="off">
</form>
web.xml文件如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>Hello world web application using PrimeFaces and Spring</display-name>
<!-- Spring Context Configuration' s Path definitions -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
/WEB-INF/spring-security.xml
</param-value>
</context-param>
<!-- The Bootstrap listener to start up and shut down Spring's root WebApplicationContext.
It is registered to Servlet Container -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
<!-- Project Stage Level -->
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<!-- Spring Security tag library for JSF -->
<context-param>
<param-name>javax.faces.FACELETS_LIBRARIES</param-name>
<param-value>/WEB-INF/springsecurity.taglib.xml</param-value>
</context-param>
<!-- Welcome Page -->
<welcome-file-list>
<welcome-file>/index.xhtml</welcome-file>
</welcome-file-list>
<!-- Spring Security filter Chain -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<!-- Filter Mappings -->
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<!-- JSF Servlet is defined to container -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Mapping with servlet and url for the http requests. -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>log4jConfig.xml</param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.enableMissingResourceLibraryDetection</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>home</param-value>
</context-param>
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>
<!--
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
-->
<mime-mapping>
<extension>css</extension>
<mime-type>text/css</mime-type>
</mime-mapping>
<mime-mapping>
<extension>js</extension>
<mime-type>text/javascript</mime-type>
</mime-mapping>
<mime-mapping>
<extension>txt</extension>
<mime-type>text/plain</mime-type>
</mime-mapping>
<mime-mapping>
<extension>gif</extension>
<mime-type>image/gif</mime-type>
</mime-mapping>
<mime-mapping>
<extension>jpeg</extension>
<mime-type>image/jpeg</mime-type>
</mime-mapping>
<mime-mapping>
<extension>jpg</extension>
<mime-type>image/jpeg</mime-type>
</mime-mapping>
<mime-mapping>
<extension>png</extension>
<mime-type>image/png</mime-type>
</mime-mapping>
<mime-mapping>
<extension>xml</extension>
<mime-type>application/xml</mime-type>
</mime-mapping>
</web-app>
保安工作。。我可以使用凭据登录。我不知道我在配置中做错了什么,也不知道为什么要添加.xhtml扩展名
任何想法都值得赞赏。PrimeFaces不会这么做。这是标准的JSF。您的Spring安全配置无效。您错误地隐式告诉它还阻止对来自/javax.faces.resource/*的CSS/JS/image资源的访问。一个简单的测试是禁用/移除弹簧安全性。您将看到CSS/JS/image资源开始工作,即它们将返回正常的HTTP 200响应,而不是登录页面。。。查看HTTP流量监视器。非常感谢!事实上,添加一个新的解决了这个问题。现在检索CSS和Javascript文件。