基于struts2的登录系统
生活随笔
收集整理的這篇文章主要介紹了
基于struts2的登录系统
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
web.xml配置
<?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" 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_3_0.xsd"><display-name></display-name> <welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list><filter><!-- 配置strus2核心控制器的名稱(chēng)--><filter-name>struts2</filter-name><!-- 配置strus2核心控制器的類(lèi) --><filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class></filter><filter-mapping><filter-name>struts2</filter-name><!-- 攔截.action的請(qǐng)求 --><url-pattern>*.action</url-pattern></filter-mapping></web-app> login.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><title>基于Strust2的登錄系統(tǒng)</title></head> <body><!-- 表單action屬性為login.action,攔截器通過(guò)此參數(shù)找到對(duì)應(yīng)的action處理請(qǐng)求 --><form action="login.action" method="post">用戶(hù)名:<input type="text" name="userName" size="24"><br>密??碼??:<input type="password" name="passWord" size="25.5"><br><input type="submit" value="登錄"></form></body> </html>
Success.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><title>登錄成功</title></head><body><hr><h1>你登錄成功,歡迎你。</h1><hr></body> </html>
loginbean.java
package LoginBean;public class LoginBean {private String userName;private String password;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;}//狐貍用戶(hù)登錄的方法public boolean login(String userName,String password){boolean b=false;if(userName.equals("QQ")&&password.equals("123")){b=true;return b;}else{b=false;return b;}} }LoginAction.java
package LoginBean;public class LoginBean {private String userName;private String password;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;}//狐貍用戶(hù)登錄的方法public boolean login(String userName,String password){boolean b=false;if(userName.equals("QQ")&&password.equals("123")){b=true;return b;}else{b=false;return b;}} } struts.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"> <struts><package name="kk" extends="struts-default"><!-- Action的配置可以有多對(duì),name是業(yè)務(wù)控制器的名稱(chēng),在表單中指定的名字需要與該名字一直,class指定Action類(lèi)的位置 --><action name="login" class="LoginAction.LoginAction"><!-- 定義兩個(gè)邏輯視圖和無(wú)力資源之間的映射,name的值是Action中的返回結(jié)果,即邏輯視圖 --><result name="success">/login/success.jsp</result><result name="error">/login/login.jsp</result></action></package> </struts>
總結(jié)
以上是生活随笔為你收集整理的基于struts2的登录系统的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Action访问Servlet API的
- 下一篇: 使用指定的Action,Category