jsf应用中,页面未能正常跳转!
请求页面未能从jsfpage.jsp跳转到jsfpage2.jsp页面,花了一整个晚上都搞不请原因所在,请高手指点!代码如下:
//web.xml
<?xml version= "1.0 " encoding= "UTF-8 "?>
<web-app id= "WebApp_ID " version= "2.4 " xmlns= "http://java.sun.com/xml/ns/j2ee " xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance " xsi:schemaLocation= "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd ">
<display-name>
simple
</display-name>
<context-param>
<param-name> javax.faces.CONFIG_FILES </param-name>
<param-value> /WEB-INF/faces-config.xml </param-value>
</context-param>
<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> index.htm </welcome-file>
<welcome-file> index.jsp </welcome-file>
<welcome-file> default.html </welcome-file>
<welcome-file> default.htm </welcome-file>
<welcome-file> default.jsp </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>
<navigation-rule>
<from-view-id> /jsfpage.jsp </from-view-id>
<navigation-case>
<from-outcome> submit </from-outcome>
<to-view-id> /jsfpage2.jsp </to-view-id>
<redirect/>
</navigation-case>
</navigation-rule>
<managed-bean>
<managed-bean-name> typedName </managed-bean-name>
<managed-bean-class> simple.practice.TypedName </managed-bean-class>
<managed-bean-scope> session </managed-bean-scope>
</managed-bean>
</faces-config>
//TypedName Bean
package simple.practice;
public class TypedName {
String name;
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
}
//jsfpage1.jsp
<%@ taglib uri = "http://java.sun.com/jsf/core " prefix = "f " %>
<%@ taglib uri = "http://java.sun.com/jsf/html " prefix = "h " %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN ">
<html>
<f:view>
<head>
<%@ page language= "java " contentType= "text/html; charset=UTF-8 "
pageEncoding= "UTF-8 "%>
<meta http-equiv= "Content-Type " content= "text/html; charset=UTF-8 ">
<title> jsf 1st try </title>
</head>
<body>
<h:form>
<table>
<tr>
<td> type your name: </td>
<td>
<h:inputText value = "#{typedName.name} "/>
</td>
</tr>
</table>
<h:commandButton value = "OK " action = "submit "/>
</h:form>
</body>
</f:view>
</html>
//jsfpage2.jsp
<%@ taglib uri = "http://java.sun.com/jsf/core " prefix = "f " %>
<%@ taglib uri = "http://java.sun.com/jsf/html " prefix = "h " %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN ">
<html>
<f:view>
<head>
<%@ page language= "java " contentType= "text/html; charset=UTF-8 "
pageEncoding= "UTF-8 "%>
<meta http-equiv= "Content-Type " content= "text/html; charset=UTF-8 ">
<title> jsf 1st try </title>
</head>
<body>
you typed the name: <h:outputText value = "#{typedName.name} "/>
</body>
</f:view>
</html>
[解决办法]
首先,jsp1没有事件监听器, <h:commandButton value = "OK " action = "submit "/>
应该改为 <h:commandButton value = "OK " action = " "#{typedName.okAction} "/>
然后,在TypedName类里面必须增加okAction事件,如:
public String okAction(){
return "submit ";//这里的返回值必须跟faces-config.xml的 <from-outcome> submit </from- //outcome> 一致
}
建议你根据eclipse中jsf例子多练几遍。
[解决办法]
up
[解决办法]
先看基础