如何在glassfish v3中部署jsf2.0应用程序

一、glassfish v3安装及配置:
1.下载glassfish v3:
这里以glassfish v3-prelude为例,从[url]https://glassfish.dev.java.net/downloads/v3-prelude.html[/url]下载glassfish v3-prelude的zip版本,解压。

2.查看已经安装的jsf实现包:
cmd>install_dir/bin/pkg list -va glassfish-jsf
从列表中即可看到jsf信息,state列为installed的是安装了的。一般来说,默认安装的是jsf1.2的实现。

3.删除jsf1.2,安装jsf2.0:
偶就是在这个地方载了跟斗,花了好长时间都没弄明白为何jsf2.0的程序不能在默认下载的glassfish v3上跑起来,把个helloworld的web.xml改了又改。而且官方网站上的What's in GlassFish v3 Prelude表格中,updatecenter明确列有jsf2.0那一行,于是我反复运行updatetool去寻找jsf2.0。。。。。。其实只要先吧jsf1.2删除,再运行updatetools,就会看到jsf 2.0了。
cmd>install_dir/bin/pkg uninstall pkg:/glassfish-jsf@1.2.xxxxxxxx
cmd>install_dir/bin/pkg install pkg:/glassfish-jsf@2.0.0xxxxxxxxxxx
具体名称可以从第一条list命令中得到。
(我没有测试过1.2和2.0是否可以同时存在,偶写了几个jsf1.2的helloworld就开始学jsf2了,jsf1.2对偶没有利用价值,呵呵。有兴趣的同学可以试试如何让glassfish v3同时运行jsf1.2和jsf2.0的应用)

二、写个hellowold测试:
(或者可直接使用mojarra-2.0.0中的example)
1.web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>testjsf2</display-name>

<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</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>*.xhtml</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>

2.managed bean

package com.demo;

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

@ManagedBean(name = "helloBean")
@SessionScoped
public class HelloWorldBean implements java.io.Serializable {
private static final long serialVersionUID = 6866250699219535733L;
private String name;

/**
* @return the name
*/
public String getName() {
this.name = "World";
return name;
}
}


3.helloworld.xhtml

<!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"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>Hello World</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 id="form">
<div
style="padding: 100px 0 0 100px; font-size: 22px; font-weight: bold">
Hello,#{helloBean.name}!</div>
</h:form>
</h:body>
</html>

本例子比较简单,所以无需faces-config.xml。参考《在Eclipse 3_5中使用JSF 2_0开发Web应用环境配置及一个简单例子(系列之二) - 砺锋文章》一文。
另外WEB-INF/lib中无需再考入mojarra-2.0.0的jsf2参考实现的两个jar,因为glassfish中已经有了。

三、运行glassfish,部署程序。
1.运行:
cmd>install_dir\glassfish\bin\startserv.bat,然后在浏览器中打开http://localhost:4848/,进入glassfish web console管理界面。
2.部署:
进入glassfish web console管理界面后,选择部署应用程序,然后选择本地文件夹部署方式,输入testjsf2的web目录,其他默认,点击确定就部署成功了。
3.测试应用程序:
直接单击部署界面,应用程序表格中的“启动”,就可以在浏览器中打开Helloworld的url地址了,点击helloworld.xhtml就看到结果了!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值