给定使用Jboss seam构建的Web应用程序,其中包含以下详细信息:
dynamic web module: 2.3
Java : 1.5
Javascript: 1.0
Tomcat: 5.0
activation.jar
commons-beanutils-1.7.0.jar
commons-codec-1.3.jar
commons-digester-1.6.jar
commons-el-1.0.jar
commons-fileupload-1.0.jar
commons-lang-2.1.jar
commons-logging-1.0.4.jar
jstl-1.1.0.jar
jxl.jar
log4j-1.2.8.jar
myfaces-api-1.1.5.jar
myfaces-impl-1.1.5.jar
standard.jar
tomahawk-1.1.3.jar
看过RichFaces及其提供的内容后,我想将它添加到应用程序中,并通过创建一个新的应用程序来尝试(并失败):
dynamic web module: 2.5
Java: 1.5
Javascript: 1.0
Tomcat : 6.0
并且我可以通过在线集合来满足Richfaces库,但也能够部署现有应用程序,我将以下库添加到新项目中:
activation.jar
common-annotations.jar
commons-beanutils-1.7.0.jar
commons-codec-1.3.jar
commons-collections-3.2.jar
commons-digester-1.8.jar
commons-discovery-0.4.jar
commons-el-1.0.jar
commons-fileupload-1.0.jar
commons-lang-2.1.jar
commons-logging-1.1.1.jar
jsf-api.jar
jsf-impl.jar
jsf-tlds.jar
jstl.jar
jxl.jar
log4j-1.2.8.jar
myfaces-api-1.2.9.jar
myfaces-impl-1.2.9.jar
richfaces-api-3.3.3.Final.jar
richfaces-impl-3.3.3.Final.jar
richfaces-ui-3.3.3.Final.jar
standard.jar
tomahawk-1.1.3.jar
我在web.xml中添加了所需的richfaces标签。我可以部署和运行应用程序,并且可以看到richfaces皮肤应用于页面上的所有控件(bluesky),但显然设置有问题。链接重定向似乎不起作用(例如从登录屏幕到主页...等)和调用backbean等时的null异常问题。从我所看到的库中,冲突可能是原因,但我保留了上述内容,因为删除myfaces或jsf jar不允许应用程序部署。
我的问题:将RichFaces和MyFaces混合起来是个坏主意(或者根本不应该这样做?)。我添加上述库的主要原因是能够运行我们的应用程序,但也添加了RichFaces,我很感激有人告诉我上面不必要的(冲突)库以及我应该遵循的正确路径来添加Richfaces这个接缝应用。
更新
正如所建议的,JSF和MyFaces库是冲突的,因此我试图删除一个并保留另一个。下面是我删除JSF库jsf-impl.jar
jsf-tlds.jar
jsf-api.jar
并保留myfaces库时出现的错误:
javax.servlet.ServletException: java.lang.NoClassDefFoundError: com/sun/faces/taglib/jsf_core/ViewTag
Caused by:
java.lang.ClassNotFoundException - com.sun.faces.taglib.jsf_core.ViewTag
- Stack Trace
javax.faces.FacesException: javax.servlet.ServletException: java.lang.NoClassDefFoundError: com/sun/faces/taglib/jsf_core/ViewTag
at org.apache.myfaces.context.servlet.ServletExternalContextImpl.dispatch(ServletExternalContextImpl.java:347)
at org.apache.myfaces.application.jsp.JspViewHandlerImpl.buildView(JspViewHandlerImpl.java:486)
从我看到的我可以看出错误来自以下标签:
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>
删除MyFaces库myfaces-api-1.2.9.jar
myfaces-impl-1.2.9.jar
并保持JSF库导致HTTP Status 404
出现以下错误:
02/11/2011 11:47:53 AM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8165
02/11/2011 11:47:53 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 432 ms
02/11/2011 11:47:53 AM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
02/11/2011 11:47:53 AM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.33
02/11/2011 11:47:54 AM org.apache.catalina.core.StandardContext addApplicationLi
stener
INFO: The listener "com.sun.faces.config.ConfigureListener" is already configure
d for this context. The duplicate definition has been ignored.
02/11/2011 11:47:54 AM org.apache.catalina.core.StandardContext start
SEVERE: Error listenerStart
02/11/2011 11:47:54 AM org.apache.catalina.core.StandardContext start
SEVERE: Context [/TestProj] startup failed due to previous errors
02/11/2011 11:47:54 AM org.apache.catalina.loader.WebappClassLoader clearReferen
cesJdbc
SEVERE: The web application [/TestProj] registered the JDBC driver [org.postgres
ql.Driver] but failed to unregister it when the web application was stopped. To
prevent a memory leak, the JDBC Driver has been forcibly unregistered.
02/11/2011 11:47:54 AM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor host-manager.xml
02/11/2011 11:47:54 AM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor manager.xml
02/11/2011 11:47:54 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory ROOT
02/11/2011 11:47:54 AM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8165
02/11/2011 11:47:54 AM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
02/11/2011 11:47:54 AM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/15 config=null
02/11/2011 11:47:54 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 767 ms
多汁的位是 SEVERE:错误listenerStart 。
下面是我使用的web.xml:
web.xml
:
<?xml version="1.0"?>
<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">
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>blueSky</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.CONTROL_SKINNING</param-name>
<param-value>enable</param-value>
</context-param>
<filter>
<display-name>RichFaces Filter</display-name>
<filter-name>richfaces</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
<filter-mapping>
<filter-name>richfaces</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
<filter>
<filter-name>MyFacesExtensionsFilter</filter-name>
<filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-
class>
<init-param>
<param-name>maxFileSize</param-name>
<param-value>20m</param-value>
</init-param>
</filter>
<!-- extension mapping for adding <script/>, <link/>, and other resource
tags to JSF-pages -->
<filter-mapping>
<filter-name>MyFacesExtensionsFilter</filter-name>
javax.faces.webapp.FacesServlet
entry -->
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<filter-mapping>
<filter-name>MyFacesExtensionsFilter</filter-name>
<url-pattern>/faces/myFacesExtensionResource/*</url-pattern>
</filter-mapping>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.PRETTY_HTML</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
<param-value>true</param-value>
</context-param>
<listener>
<listener-class>
org.apache.myfaces.webapp.StartupServletContextListener</listener-
class>
</listener>
<listener>
<listener-class>testProj.SessionExpireHandler</listener-class>
</listener>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<filter>
<filter-name>Faces Servlet</filter-name>
<filter-class>testProj.SessionHandler</filter-class>
</filter>
<filter-mapping>
<filter-name>Faces Servlet</filter-name>
<url-pattern>*.faces</url-pattern>
</filter-mapping>
<!-- Welcome files -->
<welcome-file-list>
<welcome-file>jsp/index.jsp</welcome-file>
</welcome-file-list>
<session-config>
<session-timeout>60</session-timeout>
</session-config>
</web-app>
正如所建议的那样,剩余在lib文件夹中的Mojarra的最后一位是jsf-tlds.jar
,现在已被删除。我正在运行的Tomcat版本是tomcat-6.0.33
。我还更新了myfaces to 2.1
和Tomahawk to 1.1.11
以及所有相关库.Below是更新的完整lib jar列表:
activation.jar
batik-awt-util-1.6-1.jar
batik-ext-1.6-1.jar
batik-gui-util-1.6-1.jar
batik-util-1.6-1.jar
commons-beanutils-1.7.0.jar
commons-codec-1.3.jar
commons-collections-3.2.1.jar
commons-digester-1.6.jar
commons-el-1.0.jar
commons-fileupload-1.2.1.jar
commons-io-1.3.2.jar
commons-lang-2.4.jar
commons-logging-1.1.1.jar
commons-validator-1.3.1.jar
iText-2.1.2u.jar
jstl.jar
jxl.jar
log4j-1.2.8.jar
mail.jar
myfaces-api-2.1.3.jar
myfaces-impl-2.1.3.jar
Opta2000.jar
oro-2.0.8.jar
postgresql-8.4-701.jdbc3.jar
richfaces-api-3.3.3.Final.jar
richfaces-impl-3.3.3.Final.jar
richfaces-ui-3.3.3.Final.jar
standard.jar
tomahawk20-1.1.11.jar
xml-apis-1.0.b2.jar
xmlParserAPIs-2.0.2.jar
我也删除了
<!-- Listener, that does all the startup work (configuration, init). -->
<listener>
<listener-class>
org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>
来自web.xml的(没有进行其他更改)。我可以部署应用程序,但导航到登录页面会给出HTTP Status 500 -
并抛出异常,如下所示:
[2011-11-02 15:16:50,775] ERROR: org.ajax4jsf.webapp.BaseXMLFilter - Exception in the filter chain
javax.servlet.ServletException: /jsp/login.facesNo saved view state could be found for the view identifier: /jsp/login.faces
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:205)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:357)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:206)
at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.dbschenker.util.SessionHandler.doFilter(SessionHandler.java:34)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:291)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
Caused by: javax.faces.application.ViewExpiredException: /jsp/login.facesNo saved view state could be found for the view identifier: /jsp/login.faces
at org.apache.myfaces.lifecycle.RestoreViewExecutor.execute(RestoreViewExecutor.java:128)
at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:171)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:189)
... 24 more
将myfaces降级为MyFaces Core 2.0.9
,例外情况与以下相同:
[2011-11-02 16:10:59,260] ERROR: org.ajax4jsf.webapp.BaseXMLFilter - Exception in the filter chain
javax.servlet.ServletException: /jsp/login.facesNo saved view state could be found for the view identifier: /jsp/login.faces
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:205)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:357)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:206)
at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at com.dbschenker.util.SessionHandler.doFilter(SessionHandler.java:34)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:291)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:662)
Caused by: javax.faces.application.ViewExpiredException: /jsp/login.facesNo saved view state could be found for the view identifier: /jsp/login.faces
at org.apache.myfaces.lifecycle.RestoreViewExecutor.execute(RestoreViewExecutor.java:128)
at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:171)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:189)
... 24 more
请注意这是否值得一提,但是在tomahawk和myfaces中都存在以下库:
##tomahawk#
commons-logging-1.1.1.jar
commons-beanutils-1.7.0.jar
commons-codec-1.3.jar
commons-collections-3.2.1.jar
commons-digester-1.6.jar
#myfaces 2.0.9
commons-beanutils-1.8.3.jar
commons-codec-1.3.jar
commons-collections-3.2.jar
commons-digester-1.8.jar
commons-logging-1.1.1.jar
我正在使用战斧附带的那些。
在线研究上述异常与页面提交包含不再存在的服务器端视图状态的id的会话有关。这是我的web.xml中的错误配置?请注意,我正在进行会话处理,如下所示:
的web.xml:
<listener>
<listener-class>testProj.SessionExpireHandler</listener-class>
</listener>
<filter>
<filter-name>Faces Servlet</filter-name>
<filter-class>com.dbschenker.util.SessionHandler</filter-class>
</filter>
<filter-mapping>
<filter-name>Faces Servlet</filter-name>
<url-pattern>*.faces</url-pattern>
</filter-mapping>
和SessionHandler.java
:
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class SessionHandler implements Filter {
private String timeoutPage;
public void init(FilterConfig filterConfig) throws ServletException {
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
if ((request instanceof HttpServletRequest) && (response instanceof HttpServletResponse)) {
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
HttpServletResponse httpServletResponse = (HttpServletResponse) response;
if (isSessionControlRequiredForThisResource(httpServletRequest)) {
if (isSessionInvalid(httpServletRequest)) {
try {
httpServletRequest.getSession().setAttribute("sexpiremessage", ApplicationConstant.SESSION_EXP);
RequestDispatcher rd = httpServletRequest.getRequestDispatcher("/jsp/login.faces");
String timeoutUrl = httpServletRequest.getContextPath() + "/" + getTimeoutPage();
httpServletResponse.sendRedirect(timeoutUrl);
} catch (Exception e) {
e.printStackTrace();
}
return;
}
}
}
try {
filterChain.doFilter(request, response);
} catch (Exception e) {
// e.printStackTrace();
}
}
private boolean isSessionControlRequiredForThisResource(HttpServletRequest httpServletRequest) {
String requestPath = httpServletRequest.getRequestURI();
boolean controlRequired = !(requestPath.endsWith("/login.faces"));
return controlRequired;
}
private boolean isSessionInvalid(HttpServletRequest httpServletRequest) {
boolean sessionInValid = false;
try {
sessionInValid = (httpServletRequest.getRequestedSessionId() != null) && !httpServletRequest.isRequestedSessionIdValid();
if (httpServletRequest.getSession().getAttribute(ApplicationConstant.SESSION_INFO_KEY) == null)
sessionInValid = true;
} catch (Exception e) {
e.printStackTrace();
}
return sessionInValid;
}
public void destroy() {
}
public String getTimeoutPage() {
return "jsp/login.faces";
}
public void setTimeoutPage(String timeoutPage) {
this.timeoutPage = timeoutPage;
}
}
我不清楚为什么会抛出异常!
答案 0 :(得分:1)
您正在混合JSF实现。这些来自Mojarra:
jsf-api.jar
jsf-impl.jar
jsf-tlds.jar
(我从未见过jsf-tlds.jar
,它们似乎起源于其他地方,它的/META-INF/MANIFEST.MF
文件说的是什么?) < / p>
这些来自MyFaces:
myfaces-api-1.2.9.jar
myfaces-impl-1.2.9.jar
这是不允许的。他们只会互相冲突。您应该选择并使用其中一个。
<强>更新强>:
根据您的更新,MyFaces的以下例外,
java.lang.ClassNotFoundException - com.sun.faces.taglib.jsf_core.ViewTag
建议您在类路径中的某处仍然使用Mojarra TLD文件。要么打包在JAR中(通常是jsf-impl.jar
,但是jsf-tlds.jar
非常可疑,我真的很好奇你从哪里得到它以及它们包含什么),或者是.tld
文件。换句话说,运行时类路径仍然是混乱的Mojarra和MyFaces实现。清理Webapp/WEB-INF/lib
,Webapp/WEB-INF/classes
,Tomcat/lib
,JRE/lib
等。
以下信息与Mojarra,
INFO:已为此上下文配置了侦听器“com.sun.faces.config.ConfigureListener”。重复的定义已被忽略。
这是Tomcat中的一个错误(您使用的是哪个版本?6.0.18中修复了类似的错误),或者您在<listener>
中不必要地将其重复为web.xml
。它应该已经由任何JSP 2.0兼容容器(如Tomcat 5.5及更高版本)上的TLD文件自动初始化,无论您使用的是MyFaces还是Mojarra。
Mojarra发生以下错误,
SEVERE:错误listenerStart
可能是因为您web.xml
中有MyFaces特定的侦听器而导致的:
<listener>
<listener-class>
org.apache.myfaces.webapp.StartupServletContextListener
</listener-class>
</listener>
完全删除它。在兼容JSP 2.0的容器上,MyFaces / Mojarra根本不需要它。
回到jsf-tlds.jar
,你正在使用的是什么样的Mojarra版本以及你从哪里获得它?你知道你应该从官方制造商的网站上下载libs吗? Mojarra可在http://javaserverfaces.java.net获得。那里有Tomcat 6.0兼容的1.2_15(或者最好是2.0.6)。它由2个JAR文件jsf-api.jar
和jsf-impl.jar
组成。没有神秘的jsf-tlds.jar
文件。与JSF 1.2相比,JSF 2.0提供了很多优势。如果可以,我强烈建议您也进行升级。
更新2 :你没有告诉任何关于异常的事情,所以我不能具体。但这看起来并不合适:
myfaces-api-2.1.3.jar
myfaces-impl-2.1.3.jar
JSF 2.1需要Servlet 3.0兼容容器,而Tomcat 6.0则是Servlet 2.5容器。你需要JSF 2.0。选择MyFaces 2.0.x或Mojarra 2.0.x,但不选择2.1.x.如果您确实需要JSF 2.1,请将Tomcat升级到7.0。