wtp1.53 all in one + jsf plugin
tomcat5.5.20
jdk1.6
jsf-1_1_01
jstl-1.1.2
默认(唯一)页面index.html:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<a href = "index.faces">click here to start the jsf example</a>
</body>
</html>
--------------------------------------
由index.html连接到index.jsp
index.jsp:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri = "http://java.sun.com/jsf/core" prefix = "f" %>
<%@ taglib uri = "http://java.sun.com/jsf/html" prefix = "h" %>
<html>
<f:view>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>index</title>
</head>
<body>
<h:form>
<h:inputText value = "#{user.name}"></h:inputText>
<h:commandButton value = "ok" action = "submit"></h:commandButton>
</h:form>
</body>
</f:view>
</html>
--------------------------------------
然后index.jsp在跳转到home.jsp(在faces-config.xml中配置该导航规则)
home.jsp:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri = "http://java.sun.com/jsf/core" prefix = "f" %>
<%@ taglib uri = "http://java.sun.com/jsf/html" prefix = "h" %>
<html>
<f:view>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>home</title>
</head>
<body>
<h:outputText value = "#{user.name}"></h:outputText>
</body>
</f:view>
</html>
--------------------------------------
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app id="WebApp_ID">
<display-name>jsf1</display-name>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>
javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
--------------------------------------
faces-config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE faces-config PUBLIC
"-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
"http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
<faces-config>
<managed-bean>
<managed-bean-name>
user</managed-bean-name>
<managed-bean-class>
jsf1.bean.UserBean</managed-bean-class>
<managed-bean-scope>
session</managed-bean-scope>
</managed-bean>
<navigation-rule>
<display-name>
index</display-name>
<from-view-id>
/index.jsp</from-view-id>
<navigation-case>
<from-outcome>submit</from-outcome>
<to-view-id>
/home.jsp</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
--------------------------------------
使用的UserBean:
package jsf1.bean;
public class UserBean {
String name = "your name";
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
}
在eclipse中运行正常,但是将.war export到tomcat安装路径的webapps中运行有问题,index.html正常显示,点击超连接就报错,错误如下:
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Servlet.init() for servlet Faces Servlet threw exception
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:833)
org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:639)
org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1285)
java.lang.Thread.run(Unknown Source)
root cause
java.lang.NullPointerException
javax.faces.webapp.FacesServlet.init(FacesServlet.java:144)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:833)
org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:639)
org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1285)
java.lang.Thread.run(Unknown Source)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.20 logs.
--------------------------------------
有没有谁遇到过这个问题!!!
6 个解决方案
#1
<h:commandButton value = "ok" action = "submit"></h:commandButton>
怎么没有事件监听器?应该改为<h:commandButton value = "ok" action = "#{user.testAction}"></h:commandButton>并且需要在UserBean类增加事件
public String testAction(){return "submit";}
你好象问过类似的问题了,这可是个jsf最基本的东西,eclipse有现成的例子,照着它的做,肯定会成功!
怎么没有事件监听器?应该改为<h:commandButton value = "ok" action = "#{user.testAction}"></h:commandButton>并且需要在UserBean类增加事件
public String testAction(){return "submit";}
你好象问过类似的问题了,这可是个jsf最基本的东西,eclipse有现成的例子,照着它的做,肯定会成功!
#2
其实是同样的一个问题,按你说的改也是一样的错误。另外jsf中导航规则分两种情况,一种是静态,一种是动态的,我这个就是静态的,就是直接将字符串赋予action属性实现,你说的那种是动态的,通过方法绑定语句邦定bean中的方法成员实现,也可以通过值绑定语句邦定bean中的属性成员实现,很感谢你回复
#3
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>
javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
中的load-on-startup改为-1再试试
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>
javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
中的load-on-startup改为-1再试试
#4
还是一样--!
但在eclipse中运行正常
但在eclipse中运行正常
#5
看看两者所依赖的jre是不是不一样?
#6
LZ看一下服务器的 日志 就知道了
#1
<h:commandButton value = "ok" action = "submit"></h:commandButton>
怎么没有事件监听器?应该改为<h:commandButton value = "ok" action = "#{user.testAction}"></h:commandButton>并且需要在UserBean类增加事件
public String testAction(){return "submit";}
你好象问过类似的问题了,这可是个jsf最基本的东西,eclipse有现成的例子,照着它的做,肯定会成功!
怎么没有事件监听器?应该改为<h:commandButton value = "ok" action = "#{user.testAction}"></h:commandButton>并且需要在UserBean类增加事件
public String testAction(){return "submit";}
你好象问过类似的问题了,这可是个jsf最基本的东西,eclipse有现成的例子,照着它的做,肯定会成功!
#2
其实是同样的一个问题,按你说的改也是一样的错误。另外jsf中导航规则分两种情况,一种是静态,一种是动态的,我这个就是静态的,就是直接将字符串赋予action属性实现,你说的那种是动态的,通过方法绑定语句邦定bean中的方法成员实现,也可以通过值绑定语句邦定bean中的属性成员实现,很感谢你回复
#3
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>
javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
中的load-on-startup改为-1再试试
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>
javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
中的load-on-startup改为-1再试试
#4
还是一样--!
但在eclipse中运行正常
但在eclipse中运行正常
#5
看看两者所依赖的jre是不是不一样?
#6
LZ看一下服务器的 日志 就知道了