首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

简单jsf应用在eclipse中的tomcat运行ok,export出来运行会报错,什么有关问题

2013-09-11 
简单jsf应用在eclipse中的tomcat运行ok,export出来运行会报错,什么问题!环境:wtp1.53allinone+jsfpluginto

简单jsf应用在eclipse中的tomcat运行ok,export出来运行会报错,什么问题!
环境:
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.

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

有没有谁遇到过这个问题!!!

[解决办法]
<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有现成的例子,照着它的做,肯定会成功!

[解决办法]
LZ看一下服务器的 日志 就知道了
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html

热点排行