hello1代码:
package javaeetutorial.hello1; import javax.enterprise.context.RequestScoped; import javax.inject.Named; @Named @RequestScoped public class Hello { private String name; } public String getName() { } public void setName(String user_name) { this.name = user_name; } }
package 引入包名
@named @requestscoped 用修饰器方法进行方法诸如
public class hello 定义hello类 里面的大括号内:实现功能的代码 获取name等
web.xml:<?
xml
version="1.0" encoding="UTF-8"?>
<
web-app
version="3.1"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<
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
> *servlet的位置
<
load-on-startup
>1</
load-on-startup
>
</
servlet
>
<
servlet-mapping
> *设置默认访问为xhtml
<
servlet-name
>Faces Servlet</
servlet-name
>
<
url-pattern
>*.xhtml</
url-pattern
> *浏览器通过该url找到servlet
</
servlet-mapping
>
<
session-config
> #设置超时
<
session-timeout
>
30
</
session-timeout
>
</
session-config
>
<
welcome-file-list
>
<
welcome-file
>index.xhtml</
welcome-file
>
</
welcome-file-list
>
</
web-app
>