Im第一步進入JSF框架。我這樣做,這些JSP /豆:JSF - 第一步 - Bean無法工作
的index.jsp:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Home</title>
</head>
<body>
<f:view>
<h:form>
<h:outputText value="Inserisci il tuo nome" />
<h:inputText value="#{utente.nome}" />
<h:commandButton value="Cliccami" action="avanti" />
</h:form>
</f:view>
</body>
</html>
pagina1.jsp:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!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/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Login Page</title>
</head>
<body>
<f:view>
<h:form id="LoginApplication">
<h:panelGrid id="lpg" columns="2">
<h:outputText value="Benvenuto nella tua prima pagina JSP " />
<h:outputText value="#{utente.nome}" />
</h:panelGrid>
</h:form>
</f:view>
</body>
</html>
user.java
package myPack;
public class user{
private String nome;
public user(){}
public String getNome(){
return nome;
}
public void setNome(String nome) {
this.nome=nome;
}
}
在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">
<!-- =========== FULL CONFIGURATION FILE ================================== -->
<faces-config>
<navigation-rule>
<from-view-id>/index.jsp</from-view-id>
<navigation-case>
<from-outcome>avanti</from-outcome>
<to-view-id>/pagina1.jsp</to-view-id>
</navigation-case>
</navigation-rule>
<managed-bean>
<managed-bean-name>utente</managed-bean-name>
<managed-bean-class>myPack.user</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
</faces-config>
的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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">
<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>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/index.jsp</welcome-file>
</welcome-file-list>
</web-app>
,我有這些問題: 1 - 輸入文字,我看到#{} utente.nome點擊該按鈕之前(爲什麼印刷?此刻我沒有任何東西在豆上)。 2 - 當我將它發送到服務器時,什麼也沒有發生,並且字符串「#{utente.nome}」將被打印。爲什麼?
你用什麼URL打開index.jsp?另外,你可以發佈你的web.xml內容嗎? – 2010-09-27 15:11:32
添加了web.xml代碼。我調用了http:// localhost:8084/JSFTutorial/faces/index.jsp(與http:// localhost:8084/JSFTutorial /相同) – markzzz 2010-09-27 15:50:04