1.新建dynamic web project,选择configuration,如图所示:
2.新建之后,显示如下:
3.创建
4.新建userChoose.jsp,newJava.jsp,newC.jsp
(1) userChoose.jsp
<%@page language="java"import="java.util.*"
contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%> <%@taglib uri="java.sun/jsf/core"prefix="f"%>
<%@taglib uri="java.sun/jsf/html"prefix="h"%>
<!DOCTYPE html PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN" "/TR/html4/loose.dtd">
<html>
<head>
<title>My JSF 'index.jsp' starting page</title>
</head>
<body>
JSF测试信息!
<br/>
<f:view>
<h:form>
请选择查询项目:<br/>
<h:selectOneMenu value="#{dw.type}"
valueChangeListener="#{dw.selectType}"id="selecttype">
java和jsp<f:selectItem itemValue="JAVA"itemLabel="JAVA"/>
<f:selectItem itemValue="C"itemLabel="C"/>
</h:selectOneMenu>
<h:commandButton value="提交"action="#{dw.gourl}">
</h:commandButton>
</h:form>
</f:view>
</body>
(2) newJava.jsp
<%@page language="java"contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib uri="java.sun/jsf/core"prefix="f"%>
<%@taglib uri="java.sun/jsf/html"prefix="h"%>
<!DOCTYPE html PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN" "/TR/html4/loose.dtd">
<html>
<head>
<title>My JSP 'newJava.jsp' starting page</title>
</head>
<body>
JSF测试信息!<br/>
<f:view>
<h:form>
欢迎学习<h:outputText value="#{dw.type}"></h:outputText>语言,祝你成功!<br/>
</h:form>
</f:view>
</body>
</html>
(3)newC.java
<%@page language="java"contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib uri="java.sun/jsf/core"prefix="f"%>
<%@taglib uri="java.sun/jsf/html"prefix="h"%>
<!DOCTYPE html PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN" "/TR/html4/loose.dtd">
<html>
<head>
<title>My JSP 'newC.jsp' starting page</title>
</head>
<body>
JSF测试信息!<br/>
<f:view>
<h:form>
欢迎学习<h:outputText value="#{dw.type}"></h:outputText>语言,祝你成功!<br/>
</h:form>
</f:view>
</body>
5.修改配置文件l
<!-- 配置托管Bean -->
<managed-bean>
<managed-bean-name>dw</managed-bean-name>
<managed-bean-class>com.dw.action.MyJsfAction</managed-bean-class >
<managed-bean-scope>session</managed-bean-scope> </managed-bean>
<!-- 定义导航规则与页面-->
<navigation-rule>
<from-view-id>/userChoose.jsp</from-view-id>
<navigation-case>
<from-outcome>JAVA</from-outcome>
<to-view-id>/newJava.jsp</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>C</from-outcome>
<to-view-id>/newC.jsp</to-view-id>
</navigation-case>
</navigation-rule>
<listener-class>faces.webapp.StartupServletContextLi stener</listener-class>
</listener>
<!-- 配置JSF的配置文件-->
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/l</param-value> </context-param>
<!-- 处理请求的servlet -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup>0</load-on-startup>
</servlet>
<!-- 配置所有.jsf结尾的请求都由JSF处理-->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
7.Run on server,浏览器访问localhost:8080/FirstJSFTestProject/userChoose.jsf(否则,
会报错!)
备注:
1.需要注意将jsp文件放置在webcontent目录下,否则不到。
2.需要导入jstl的jar包,否则,会报错java.lang.NoClassDefFoundError:
javax/servlet/jsp/jstl/core/Config。
3.项目代码结构:
4.Jar下载链接:/dist/jakarta/taglibs/standard/binaries/

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。