struts2的自定义验证框架——示例代码

来源:互联网 发布:李腾飞 java 编辑:程序博客网 时间:2024/06/05 10:16

记录一个简单的struts2登录验证框架

struts.xml

<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"    "http://struts.apache.org/dtds/struts-2.0.dtd"><struts>    <!-- 热加载 -->    <constant name="struts.devMode" value="true"></constant>    <!-- post编码 -->    <constant name="struts.i18n.encoding" value="utf-8"></constant>    <constant name="struts.ui.theme" value="simple" />     <package name="Use" namespace="/" extends="struts-default">        <action name="User_*" class="house.rent.action.UserAction"            method="{1}">            <result name="login">page/house_list.jsp</result>            <result name="err">page/login.jsp</result>            <result name="logout">page/house_list.jsp</result>            <result name="register_ok">page/house_list.jsp</result>            <result name="register_no">page/register.jsp</result>            <result name="ajaxlogin">page/ajaxmanage.jsp</result>            <result name="input">page/register.jsp</result>        </action>    </package>    <package name="default" namespace="/" extends="struts-default">    <!--    <interceptors>            定义权限检查的拦截器            <interceptor name="myAuthorization"                class="house.rent.interceptor.AuthorizationInterceptor" />            <interceptor-stack name="myStack">                <interceptor-ref name="defaultStack" />                <interceptor-ref name="myAuthorization" />            </interceptor-stack>        </interceptors>        定义默认的拦截器        <default-interceptor-ref name="myStack" /> -->        <global-results>            <result name="error">error.jsp</result>            <result name="login">/page/login.jsp</result>        </global-results>        <action name="House_*" class="house.rent.action.HouseAction"            method="{1}">            <result name="searchHouse">page/house_list.jsp</result>            <result name="pagefind">page/house_list.jsp</result>        </action>        <action name="Houses_*" class="house.rent.action.HouseActionA"            method="{1}">            <result name="addhouse">page/house_list.jsp</result>            <result name="add">page/add.jsp</result>            <result name="findByUser">page/manage.jsp</result>        </action>    </package></struts>**UserAction-validation.xml**

**Action.java**

package house.rent.action;

import house.rent.biz.UserBiz;
import house.rent.biz.impl.UserBizImpl;
import house.rent.entity.User;

import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

/**
* @author Administrator
* @version 1.0 create :2017年10月20日
* 功能:
*/
public class UserAction extends ActionSupport {
private User user;
private String ajax;
private String repassword;
/**f
* 登录
* @return
*/
public String login(){
UserBiz ub=new UserBizImpl();
System.out.println(this.getUser().getUsername());
User user=ub.login(this.getUser().getUsername(),this.getUser().getPassword());
if(user!=null&&”ajax”.equals(ajax)){
Map

原创粉丝点击