框架搭建
2015-10-08 23:02
549 查看
1.新建Dynamic Web项目JSFDemo01;
2.添加jar
3.新建Login类
输入:admin,admin,登录:
输入:admin,1111,登录:
2.添加jar
3.新建Login类
package com.demo.test.jsf; public class Login { private String username; private String password; public String login() { System.out.println("username:" + username + "; passsword:" + password); if("admin".equals(username) && "admin".equals(password)) { return "success"; } return "fail"; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } }4.在web.xml中添加一下内容
<display-name>JSFDemo01</display-name> <context-param> <param-name>javax.faces.CONFIG_FILES</param-name> <param-value>/WEB-INF/faces-config.xml</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>*.jsf</url-pattern> </servlet-mapping>5.在WEB-INF下新建faces-config.xml
<?xml version='1.0' encoding='UTF-8'?> <faces-config 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-facesconfig_1_2.xsd" version="1.2"> <managed-bean> <managed-bean-name>login</managed-bean-name> <managed-bean-class> com.demo.test.jsf.Login </managed-bean-class> <managed-bean-scope>request</managed-bean-scope> </managed-bean> <navigation-rule> <from-view-id>/login.jsp</from-view-id> <navigation-case> <from-outcome>success</from-outcome> <to-view-id>/success.jsp</to-view-id> </navigation-case> <navigation-case> <from-outcome>fail</from-outcome> <to-view-id>/fail.jsp</to-view-id> </navigation-case></navigation-rule> <navigation-rule> <from-view-id>/success.jsp</from-view-id> </navigation-rule> <navigation-rule> <from-view-id>/fail.jsp</from-view-id> </navigation-rule></faces-config>6.新建login.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSF 'login.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <f:view> <br> <h:form> <h:panelGrid columns="2"> <h:outputLabel value="username:" /> <h:inputText id="username" value="#{login.username}" required="true" /> <h:outputLabel value="password:" /> <h:inputSecret id="password" value="#{login.password}" required="true" /> </h:panelGrid> <h:panelGrid> <h:panelGroup> <h:commandButton value="Login" action="#{login.login}" /> </h:panelGroup> </h:panelGrid> </h:form> </f:view> </body> </html>7.新建success.jsp,fail.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> This is the success.jsp; </body> </html>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> This is the fail.jsp; </body> </html>8.部署,启动,访问:http://localhost:8080/JSFDemo01/login.jsf
输入:admin,admin,登录:
输入:admin,1111,登录:
相关文章推荐
- java对世界各个时区(TimeZone)的通用转换处理方法(转载)
- java-注解annotation
- java-模拟tomcat服务器
- java-用HttpURLConnection发送Http请求.
- java-WEB中的监听器Lisener
- Android IPC进程间通讯机制
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- GUI - Web前端开发框架
- 介绍一款信息管理系统的开源框架---jeecg
- Extjs4.0 最新最全视频教程
- 聚类算法之kmeans算法java版本
- java实现 PageRank算法
- PropertyChangeListener简单理解
- 插入排序
- 冒泡排序
- 堆排序