使用JavaServer Faces技术的Web模块:hello1 example
该hello1应用程序是一个Web模块,它使用JavaServer Faces技术来显示问候语和响应。您可以使用文本编辑器查看应用程序文件,也可以使用NetBeans IDE。
此应用程序的源代码位于tut-install/examples/web/jsf/hello1/目录中。
查看hello1
- index.xhtml文件是Facelets应用程序的默认登录页面。在典型的Facelets应用程序中,网页是在XHTML中创建的。对于此应用程序,页面使用简单的标记标记来显示带有图形图像,标题,字段和两个命令按钮的表单。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>Facelets Hello Greeting</title>
</h:head>
<h:body>
<h:form>
<h:graphicImage url="#{resource['images:duke.waving.gif']}"
alt="Duke waving his hand"/>
<h2>Hello, my name is Duke. What's yours?</h2>
<h:inputText id="username"
title="My name is: "
value="#{hello.name}"
required="true"
requiredMessage="Error: A name is required."
maxlength="25" />
<p></p>
<h:commandButton id="submit" value="Submit" action="response">
</h:commandButton>
<h:commandButton id="reset" value="Reset" type="reset">
</h:commandButton>
</h:form>
...
</h:body>
</html>
页面上最复杂的元素是inputText字段。该maxlength属性指定字段的最大长度。该required属性指定必须填写该字段; requiredMessage如果字段为空,则该属性提供要显示的错误消息。该title属性提供屏幕阅读器用于视觉禁用的文本。最后,该value属性包含将由Hello托管bean 提供的表达式。
Web页面Hello通过Expression Language(EL)值表达式连接到托管bean,该表达式从托管bean中#{hello.name}检索name属性的值。请注意使用hello引用托管bean Hello。如果@Named在托管bean 的注释中未指定名称,则始终使用小写的类名的第一个字母访问托管bean。
Submit commandButton元素将操作指定为response,表示单击按钮时,将response.xhtml显示该页面。
2. 查看response.xhtml文件
出现响应页面。甚至比问候页面简单,响应页面包含一个图形图像,一个显示托管bean提供的表达式的标题,以及一个按钮,其action元素将您传回index.xhtml页面:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>Facelets Hello Response</title>
</h:head>
<h:body>
<h:form>
<h:graphicImage url="#{resource['images:duke.waving.gif']}"
alt="Duke waving his hand"/>
<h2>Hello, #{hello.name}!</h2>
<p></p>
<h:commandButton id="back" value="Back" action="index" />
</h:form>
</h:body>
</html>
- 查看hello1.java文件
在Hello类,称为管理bean类,提供了getter和setter方法name中的Facelets页面表达式中使用属性。默认情况下,表达式语言引用类名,第一个字母为小写(hello.name)。
package javaeetutorial.hello1;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
@Named
@RequestScoped
public class Hello {
private String name;
public Hello() {
}
public String getName() {
return name;
}
public void setName(String user_name) {
this.name = user_name;
}
}
如果使用bean类的默认名称,则可以指定@Model为注释,而不必同时指定@Named和@RequestScoped。
3. 查看web.xml
该web.xml文件包含Facelets应用程序所需的几个元素。使用NetBeans IDE创建应用程序时,将自动创建以下所有内容
- 指定项目阶段的上下文参数:
<context-param>
<param-name> javax.faces.PROJECT_STAGE </ param-name>
<param-value> Development </ param-value>
</ context-param>
上下文参数提供Web应用程序所需的配置信息。应用程序可以定义自己的上下文参数。此外,JavaServer Faces技术和Java Servlet技术定义了应用程序可以使用的上下文参数。
- 一个servlet元素及其servlet-mapping元素指定FacesServlet。所有带.xhtml后缀的文件都将匹配
<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> *。xhtml </ url-pattern>
</ servlet-mapping>
- 一个welcome-file-list元素指定着陆页的位置:
<welcome-file-list>
<welcome-file> index.xhtml </ welcome-file>
</ welcome-file-list>
使用JavaServer Faces技术的Web模块:hello1 example的更多相关文章
- web.xml hello1代码分析
在“Web页”节点下,展开WEB-INF节点,然后双击web.xml文件进行查看. 上下文参数提供Web应用程序所需的配置信息.应用程序可以定义自己的上下文参数.此外,JavaServer Faces ...
- JSF(JavaServer Faces)简介
JavaServer Faces (JSF) 是一种用于构建Java Web 应用程序的标准框架(是Java Community Process 规定的JSR-127标准).它提供了一种以组件为中心的 ...
- JavaServer Faces 2.2 requires Dynamic Web Module 2.5 or newer
Description Resource Path Location Type JavaServer Faces 2.2 can not be installed : One or more cons ...
- 解决JavaServer Faces 2.2 requires Dynamic Web Module 2.5 or newer问题
** 错误1: **在eclipse中新创建一个web项目的时候项目下的JSP文件中会爆出错误:The superclass “javax.servlet.http.HttpServlet” was ...
- JavaServer Faces 2.0 can not be installed解决方案
问题描述:maven项目出现如下错误 JavaServer Faces 2.0 requires Dynamic Web Module 2.5 or newer..Maven Java EE Conf ...
- 20155324《网络对抗技术》web安全基础实践
20155324<网络对抗技术>web安全基础实践 实验内容 使用webgoat进行XSS攻击.CSRF攻击.SQL注入 实验问答 SQL注入攻击原理,如何防御 ①SQL注入攻击是攻击者在 ...
- JavaServer Faces (JSF) with Spring
JavaServer Faces (JSF) with Spring Last modified: April 30, 2018 by baeldung Spring+ Spring MVC JSF ...
- 20145325张梓靖 《网络对抗技术》 Web安全基础实践
20145325张梓靖 <网络对抗技术> Web安全基础实践 实验内容 使用webgoat进行XSS攻击.CSRF攻击.SQL注入 XSS攻击:Stored XSS Attacks.Ref ...
- 20145325张梓靖 《网络对抗技术》 Web基础
20145325张梓靖 <网络对抗技术> Web基础 实验内容 开启apahce,设计web前端HTML 设计web前端javascipt 设计web后端mysql 设计web后端php ...
随机推荐
- 17.3.12---logging日志模块level配置操作
1----logging日志记录模块的使用和配置 logging模块我们不需要单独再安装,经常要调试程序,记录程序运行过程中的一些信息,手工记录调试信息很麻烦,所以python的logging模块,会 ...
- Servlet&JSP复习笔记 03
1.Servlet的声明周期 容器如何创建Servlet对象,如何为Servlet对象分配资源,如何调用Servlet对象的方法来处理请求,以及如何销毁Servlet对象的过程. a.实例化 容器调用 ...
- 完成在本机远程连接HBase进行数据增删改查
1.进行hbase与本机远程连接测试连接 1.1 修改虚拟机文件hbase-site.xml(cd/usr/local/hbase/conf)文件,把localhost换成你的虚拟机主机名字 1.2修 ...
- 参考JDK1.8源码,自己写一个类似于ArrayList的动态数组
1. ArrayList的基本实现原理 ArrayLiST其内部用一个普通数组来存储数据,当此数组不够容纳新添加的元素的时候,则创建一个更大长度的新数组,并将原来数组中的元素复制到新数组中. 2.Ar ...
- 创建Git仓库
创建Git仓库 一.什么是版本仓库 什么是版本库呢?版本库又名仓库,英文名repository,你可以简单理解成一个目录,这个目录里面的所有文件都可以被Git管理起来,每个文件的修改.删除,Git都能 ...
- 初次运行Git前的配置
初次运行Git前的配置 一.初次运行 Git 前的配置 一般在新的系统上,我们都需要先配置下自己的 Git 工作环境.配置工作只需一次,以后升级时还会沿用现在的配置.当然,如果需要,你随时可以用相同的 ...
- vue 常用知识点
1.数据变更,页面渲染完成 this.$nextTick(function(){ alert('v-for渲染已经完成') }) 2.iview select组件 setQuery用法 <Sel ...
- 2019牛客暑期多校训练营(第五场)B.generator 1
传送门:https://ac.nowcoder.com/acm/contest/885/B 题意:给出,由公式 求出 思路:没学过矩阵快速幂.题解说是矩阵快速幂,之后就学了一遍.(可以先去学一下矩阵快 ...
- Opencv笔记(六)——把滑动条当调色板
学习目标: 学会把滑动条绑定到 OpenCV 的窗口. 学习函数:cv2.getTrackbarPos(), cv2.creatTrackbar()等. 简单演示: 通过调节滑动条来设定画板颜色.我们 ...
- String Distance and Transform Process
http://acm.hdu.edu.cn/showproblem.php?pid=1516 Problem Description String Distance is a non-negative ...