构建你自己的应用程序
XML:namespace prefix = o ns = "urn:schemas-microsoft-com:Office:office" />
这一部分具体讲述如何一步一步地创建你自己的JavaServer Faces应用。我所使用的例子很简单,它要求用户输入他(她)的名字,然后点击Submit按钮,然后应用程序会向用户显示一个欢迎的信息。
hello
src
web
WEB-INF
web.xml
lib
classes
这个目录结构的基本意思是说,我想创建一个叫做hello的新应用程序。在hello子目录下,有一个src子目录,里面放所有的Java 源文件;还有一个web子目录,该目录下有一个WEB-INF目录,里面包含web.xml文件及另外两个子目录,分别是lib和classes。
代码1: web.xml
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<!-- Used to initialize and destroy the application helper and register a Renderer to a RenderKit -->
<!-- Faces Servlet -->
<!-- FaceServlet should be loaded when the application starts up -->
<!-- Faces Servlet Mapping. Map the path to the servlet when a request for
the servlet is received -->
首先我们写一个 index.html 页面,这是用户进入这个应用程序的第一个页面。这个页面里面有一个超级连接,点击它可以启动应用程序。代码如下:
代码2: index.html
w3c//dtd html 4.0 transitional//en">
Mozilla/4.75 [en] (WinNT; U) .NETscape]">
Click JSP">here to start the application.
当用户点击了“here”,系统就会装载“index.jsp”,代码如下:
代码3: index.jsp
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
modelReference="UserNameBean.userName"/> 这个JSP页面有几个值得注意的地方: 模型对象bean 就像其它JavaBean组件一样:它有一组访问方法。下面的代码段显示了我们这个应用中要使用的JavaBean组件。 代码4: UserNameBean.java public class UserNameBean { String userName = null; public UserNameBean () { } public void setUserName(String user_name) { userName = user_name; } public String getUserName() { return userName; } } <未完待续> 其余部分请参考: ASP?id=18705">http://www.csdn.net/develop/read_article.asp?id=18705 用JavaServer Faces开发Web应用(1) http://www.csdn.net/develop/read_article.asp?id=18707 用JavaServer Faces开发Web应用(2) http://www.csdn.net/develop/read_article.asp?id=18710 用JavaServer Faces开发Web应用(4) http://www.csdn.net/develop/read_article.asp?id=18712 用JavaServer Faces开发Web应用(5)
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/10752019/viewspace-980897/ ,如需转载,请注明出处,否则将追究法律责任。