JSF探索--ajax应用

index.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core">
	<h:head>
		<title>welcome</title>
		<meta http-equiv="keywords" content="enter,your,keywords,here" />
		<meta http-equiv="description" content="A short description of this page." />
		<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	</h:head>
	<h:body>
		<h:form prependId="false"> 
			<h3>请输入用户名和密码</h3>
			<table>
				<tr>
					<td>姓名:</td>
					<td><h:inputText value="#{user.name}" id="name"></h:inputText></td>
				</tr>
				<tr>
					<td>密码:</td>
					<td><h:inputSecret value="#{user.password}" id="password"></h:inputSecret></td>
				</tr>
			</table>
			<p>
				<h:commandButton value="Login">
					<f:ajax execute="name password" render="out"></f:ajax>
				</h:commandButton>
			</p>
			<h3><h:outputText id="out" value="#{user.greeting}"/></h3>
		</h:form>
	</h:body>
</html>

UserBean

package com.corejsf;


import java.io.Serializable;


import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;


@ManagedBean(name="user")
@SessionScoped
public class UserBean implements Serializable{
	private static final long serialVersionUID = 1L;
	private String name;
	
	private String password;
	
	private String greeting;
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public String getGreeting() {
		if(name == null)
			return " ";
		return "welcome to jsf2+ajax"+name+"!";
	}
	public void setGreeting(String greeting) {
		this.greeting = greeting;
	}
}

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
  <display-name></display-name>
  <welcome-file-list>
    <welcome-file>faces/index.xhtml</welcome-file>
  </welcome-file-list>
  <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>
  <context-param>
  	<param-name>javax.faces.PROJECT_STAGE</param-name>
  	<param-value>DEVELOPMENT</param-value>
  </context-param>
</web-app>


工程目录结构


URL

http://localhost:8080/JSFDemo1/faces/login/web/index.xhtml

页面效果


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值