`
ghost_fly
  • 浏览: 111032 次
  • 性别: Icon_minigender_1
  • 来自: 长沙
社区版块
存档分类
最新评论

spring Hibernate struts整合配置(二)

阅读更多

上一篇讲到DAO的配置,里面涉及到一些基本类,如下:

OSCacheProvider.java

public class OSCacheProvider implements CacheProvider {

	/**
	 * The <tt>OSCache</tt> refresh period property suffix.
	 */
	public static final String OSCACHE_REFRESH_PERIOD = "refresh.period";
	/**
	 * The <tt>OSCache</tt> CRON expression property suffix.
	 */
	public static final String OSCACHE_CRON = "cron";

	private static final Properties OSCACHE_PROPERTIES = new Config().getProperties();

	/**
	 * Builds a new {@link Cache} instance, and gets it's properties from the OSCache {@link Config}
	 * which reads the properties file (<code>oscache.properties</code>) from the classpath.
	 * If the file cannot be found or loaded, an the defaults are used.
	 *
	 * @param region
	 * @param properties
	 * @return
	 * @throws CacheException
	 */
	public Cache buildCache(String region, Properties properties) throws CacheException {

		int refreshPeriod = PropertiesHelper.getInt(
			StringHelper.qualify(region, OSCACHE_REFRESH_PERIOD),
			OSCACHE_PROPERTIES,
			CacheEntry.INDEFINITE_EXPIRY
		);
		String cron = OSCACHE_PROPERTIES.getProperty( StringHelper.qualify(region, OSCACHE_CRON) );

		// construct the cache
        return new OSCache(refreshPeriod, cron, region);
	}

	public long nextTimestamp() {
		return Timestamper.next();
	}

	public boolean isMinimalPutsEnabledByDefault() {
		return false;
	}

	/**
	 * Callback to perform any necessary cleanup of the underlying cache implementation
	 * during SessionFactory.close().
	 */
	public void stop() {
	}

	/**
	 * Callback to perform any necessary initialization of the underlying cache implementation
	 * during SessionFactory construction.
	 *
	 * @param properties current configuration settings.
	 */
	public void start(Properties properties) throws CacheException {
	}
}

 

BaseDAO.java

public class BaseDAO extends AbstractDaoSupport implements DAO
{
    protected final Log log = LogFactory.getLog(getClass());

    /**
     * @see com.timeson.framework.dao.DAO#saveObject(Object)
     */
    public void saveObject(Object o)
    {
        getHibernateTemplate().saveOrUpdate(o);
    }

    /**
     * @see com.timeson.framework.dao.DAO#getObject(Class, java.io.Serializable)
     */
    public Object getObject(Class clazz, Serializable id)
    {
        Object o = getHibernateTemplate().get(clazz, id);

        if(o == null)
        {
            throw new ObjectRetrievalFailureException(clazz, id);
        }

        return o;
    }

    /**
     * @see com.timeson.framework.dao.DAO#getObjects(Class)
     */
    public List getObjects(Class clazz)
    {
        return getHibernateTemplate().loadAll(clazz);
    }

    /**
     * @see com.timeson.framework.dao.DAO#removeObject(Class, java.io.Serializable)
     */
    public void removeObject(Class clazz, Serializable id)
    {
        getHibernateTemplate().delete(getObject(clazz, id));
    }
}

 

 

DAO.java

 

public interface DAO
{

    /**
     * Generic method used to get all objects of a particular type. This
     * is the same as lookup up all rows in a table.
     *
     * @param clazz the type of objects (a.k.a. while table) to get data from
     * @return List of populated objects
     */
    public List getObjects(Class clazz);

    /**
     * Generic method to get an object based on class and identifier. An
     * ObjectRetrievalFailureException Runtime Exception is thrown if
     * nothing is found.
     *
     * @param clazz model class to lookup
     * @param id    the identifier (primary key) of the class
     * @return a populated object
     * @see com.springframework.orm.ObjectRetrievalFailureException
     */
    public Object getObject(Class clazz, Serializable id);

    /**
     * Generic method to save an object - handles both update and insert.
     *
     * @param o the object to save
     */
    public void saveObject(Object o);

    /**
     * Generic method to delete an object based on class and id
     *
     * @param clazz model class to lookup
     * @param id    the identifier (primary key) of the class
     */
    public void removeObject(Class clazz, Serializable id);
}

 

spring

 

applicationContext-service.xml

 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
    "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
    <bean id="txProxyTemplate" abstract="true"
        class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
        <property name="transactionManager" ref="transactionManager"/>
        <property name="transactionAttributes">
            <props>
                <prop key="save*">PROPAGATION_REQUIRED</prop>
                <prop key="Send*">PROPAGATION_REQUIRED</prop>
                <prop key="Complete*">PROPAGATION_REQUIRED</prop>
                <prop key="complete*">PROPAGATION_REQUIRED</prop>
                <prop key="Finish*">PROPAGATION_REQUIRED</prop>
                <prop key="finish*">PROPAGATION_REQUIRED</prop>
                <prop key="Require*">PROPAGATION_REQUIRED</prop>
                <prop key="send*">PROPAGATION_REQUIRED</prop>
                <prop key="remove*">PROPAGATION_REQUIRED</prop>
                <prop key="delete*">PROPAGATION_REQUIRED</prop>
                <prop key="add*">PROPAGATION_REQUIRED</prop>
                <prop key="update*">PROPAGATION_REQUIRED</prop>
                <prop key="*">PROPAGATION_REQUIRED</prop>
            </props>
        </property>
    </bean>

    <!-- Generic manager that can be used to do basic CRUD operations on any objects -->
    <bean id="manager" parent="txProxyTemplate">
        <property name="target">
            <bean class="BaseManager">
                <property name="DAO" ref="dao"/>
            </bean>
        </property>
    </bean>

    

    </beans>

 

涉及到的类

 

BaseManager.java

 

public class BaseManager implements Manager
{
    protected final Log log = LogFactory.getLog(getClass());
    protected DAO dao = null;

    /**
     * @see com.timeson.framework.service.Manager#setDAO(com.timeson.framework.dao.DAO)
     */
    public void setDAO(DAO dao)
    {
        this.dao = dao;
    }

    /**
     * @see com.timeson.framework.service.Manager#getObject(java.lang.Class, java.io.Serializable)
     */
    public Object getObject(Class clazz, Serializable id)
    {
        return dao.getObject(clazz, id);
    }

    /**
     * @see com.timeson.framework.service.Manager#getObjects(java.lang.Class)
     */
    public List getObjects(Class clazz)
    {
        return dao.getObjects(clazz);
    }

    /**
     * @see com.timeson.framework.service.Manager#removeObject(java.lang.Class, java.io.Serializable)
     */
    public void removeObject(Class clazz, Serializable id)
    {
        dao.removeObject(clazz, id);
    }

    /**
     * @see com.timeson.framework.service.Manager#saveObject(java.lang.Object)
     */
    public void saveObject(Object o)
    {
        dao.saveObject(o);
    }
}

 

Manager.java

 

public interface Manager
{

    /**
     * Expose the setDAO method for testing purposes
     *
     * @param dao
     */
    public void setDAO(DAO dao);

    /**
     * Generic method used to get a all objects of a particular type.
     *
     * @param clazz the type of objects
     * @return List of populated objects
     */
    public List getObjects(Class clazz);

    /**
     * Generic method to get an object based on class and identifier.
     *
     * @param clazz model class to lookup
     * @param id    the identifier (primary key) of the class
     * @return a populated object
     * @see com.springframework.orm.ObjectRetrievalFailureException
     */
    public Object getObject(Class clazz, Serializable id);

    /**
     * Generic method to save an object.
     *
     * @param o the object to save
     */
    public void saveObject(Object o);

    /**
     * Generic method to delete an object based on class and id
     *
     * @param clazz model class to lookup
     * @param id    the identifier of the class
     */
    public void removeObject(Class clazz, Serializable id);
}

 

 

struts

 

<struts-config.xml

 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
        "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">
<struts-config>

    <!--uncommnet this node if neccessary-->
    <global-forwards>
        <forward name="systemfailure" path="/WEB-INF/jsp/common/errors.jsp"   contextRelative="true"/>
        <forward name="failure" path="/WEB-INF/jsp/common/errors.jsp" contextRelative="true"/>
        <forward name="userfailure" path="/indexTbMainInfopublish.do?method=getInfoTypeListindex" contextRelative="true"/>
        <forward name="sessionfailure" path="/WEB-INF/jsp/common/SessionError.jsp" contextRelative="true"/>
        <forward name="accessfailure" path="/WEB-INF/jsp/common/privilegeErrors.jsp" contextRelative="true"/>
    </global-forwards>

    <controller nocache="true" inputForward="true" maxFileSize="2M"/>

                                                                                        
    <!-- ========== Messages Location =================================== -->
    <message-resources factory="com.timeson.framework.util.MultiMessageResourcesFactory"
                       parameter="ApplicationResources"
/>

<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
            <set-property property="pathnames"
                          value="/WEB-INF/config/validator/validator-rules.xml"/>

 </plug-in>
</struts-config>

struts-config-oa-sso.xml

 

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
        "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">

<struts-config>
    <form-beans>
        <form-bean name="ssoSinulateForm" type="org.apache.struts.action.DynaActionForm">
            <form-property name="userID" type="java.lang.String"/>
        </form-bean>
        <form-bean name="ssoLoginForm" type="org.apache.struts.action.DynaActionForm">
            <form-property name="userID" type="java.lang.String"/>
            <form-property name="userName" type="java.lang.String"/>
            <form-property name="password" type="java.lang.String"/>
            <form-property name="orgId" type="java.lang.String"/>
            <form-property name="company" type="java.lang.String"/>
            <form-property name="companyId" type="java.lang.String"/>
            <form-property name="temUserName" type="java.lang.String"/>
            <form-property name="temUserId" type="java.lang.String"/>
            <form-property name="codeStr" type="java.lang.String"/>
        </form-bean>

        <form-bean name="awokeSwitchForm" type="org.apache.struts.action.DynaActionForm">
            <form-property name="awokeSwitchBean" type="com.timeson.oa.sso.model.SysAwokeSwitch"/>
            <form-property name="userName" type="java.lang.String"/>
        </form-bean>

        <form-bean name="TbMenuForm" type="org.apache.struts.validator.DynaValidatorForm">
            <form-property name="idArr" type="java.lang.String[]"/>
            <form-property name="id" type="java.lang.String"/>
            <form-property name="menuId" type="java.lang.String"/>
            <form-property name="menuPid" type="java.lang.String"/>
            <form-property name="menuName" type="java.lang.String"/>
            <form-property name="menuUrl" type="java.lang.String"/>
            <form-property name="menuTitle" type="java.lang.String"/>
            <form-property name="menuTarget" type="java.lang.String"/>
            <form-property name="menuIcon" type="java.lang.String"/>
            <form-property name="menuIconopen" type="java.lang.String"/>
            <form-property name="menuOpen" type="java.lang.String"/>
            <form-property name="roleId" type="java.lang.Integer"/>
        </form-bean>



    </form-beans>

    <action-mappings>
        <action path="/redirectToSSO"
                parameter="/WEB-INF/jsp/sso/ssoEntry.jsp"
                type="org.apache.struts.actions.ForwardAction"/>

        <action path="/loginMailSys"
                name="ssoSinulateForm"
                parameter="method"
                scope="request"
                type="com.timeson.oa.sso.web.SsoAction">
            <forward name="ssoForWard" path="/WEB-INF/jsp/sso/ssoForward.jsp"/>
            <forward name="failure" path="/WEB-INF/jsp/sso/ssoFailure.jsp"/>
        </action>

        <action path="/loginOtherSys"
                name="ssoSinulateForm"
                parameter="method"
                scope="request"
                type="com.timeson.oa.sso.web.SsoAction">
            <forward name="ssoForWard" path="/WEB-INF/jsp/sso/ssoForward.jsp"/>
        </action>

        <action path="/getawokeSwitch"
                name="awokeSwitchForm"
                parameter="method"
                scope="request"
                type="com.timeson.oa.sso.web.TbMenuAction">
            <forward name="getSysAwokeSwitch" path="/WEB-INF/jsp/sso/awokeSwitch.jsp"/>
        </action>
        <action path="/IniResetpwd"
                parameter="/WEB-INF/jsp/sso/resetpwd.jsp"
                type="org.apache.struts.actions.ForwardAction">
        </action>
        
        <action path="/loginOASys"
                name="ssoLoginForm"
                parameter="method"
                scope="request"
                type="com.timeson.oa.sso.web.SsoAction">
            <forward name="successPro" path="/interFaceList.do?method=index" redirect="true"/>
            <!--<forward name="success" path="/WEB-INF/jsp/homepage/index.html"/>-->
            <forward name="success" path="/WEB-INF/jsp/new_homepage/new_index.html"/>

            <forward name="resetpwd" path="/WEB-INF/jsp/sso/resetpwd.jsp"/>
            <forward name="changeCompany" path="/WEB-INF/jsp/sso/resetpwd.jsp"/>
            <forward name="loginMail" path="/WEB-INF/jsp/new_default/loginMail.jsp"/>
            <forward name="error" path="/WEB-INF/jsp/common/errors.jsp" contextRelative="true" redirect="false"/>

            <forward name="userList" path="/WEB-INF/jsp/sso/userList.jsp"/>
            <forward name="switchCompany" path="/WEB-INF/jsp/sso/switchCompany.jsp"/>
        </action>
        <action path="/listTbMenu"
                name="TbMenuForm"
                parameter="method"
                scope="request"
                type="com.timeson.oa.sso.web.TbMenuAction"
                validate="false" >
         <forward name="list.success" path="/WEB-INF/jsp/sysmgmt/menu/TbMenuList.jsp"/>
         <forward name="add" path="/WEB-INF/jsp/sysmgmt/menu/TbMenuForm.jsp"/>
         </action>

        <action path="/editTbMenu"
                name="TbMenuForm"
                parameter="method"
                scope="request"
                type="com.timeson.oa.sso.web.TbMenuAction"
                validate="false" >

         <forward name="add" path="/WEB-INF/jsp/sysmgmt/menu/TbMenuForm.jsp"/>
         <forward name="edit.suceess" path="/WEB-INF/jsp/sysmgmt/menu/TbMenuForm.jsp"/>
         </action>
          <action path="/searchLog"
               name="ssoLoginForm"
                parameter="method"
                scope="request"
                type="com.timeson.oa.sso.web.SsoAction">
              <forward name="init" path="/WEB-INF/jsp/homepage/searchLoginLog.jsp"/>
              <forward name="list" path="/WEB-INF/jsp/homepage/searchLoginLogList.jsp"/>

                </action>
        <action path="/lock"
               name="TbMenuForm"
                parameter="method"
                scope="request"
                type="com.timeson.oa.sso.web.SsoAction">

              <forward name="list" path="/WEB-INF/jsp/homepage/lockUser.jsp"/>
              <forward name="searchList" path="/WEB-INF/jsp/homepage/searchLockUser.jsp"/>
              <forward name="init" path="/WEB-INF/jsp/homepage/lockSearch.jsp"/>
                </action>

        <action path="/eiacLogin"
                parameter="/WEB-INF/jsp/sso/eiacLogin.jsp"
                type="org.apache.struts.actions.ForwardAction"/>

        <action path="/loginOASysEiac"
                name="TbMenuForm"
                parameter="method"
                scope="request"
                type="com.timeson.oa.sso.web.SsoAction">

            <forward name="success" path="/WEB-INF/jsp/new_homepage/eaicIndex.jsp"/>
            <forward name="infoList" path="/WEB-INF/jsp/new_homepage/eaicInfoList.jsp"/>

        </action>

    </action-mappings>
</struts-config>

 

validator-rules.xml

 

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE form-validation PUBLIC "-//Apache Software Foundation//DTD
  Commons Validator Rules Configuration 1.1//EN"
        "http://jakarta.apache.org/commons/dtds/validator_1_1.dtd">
<!--
  $Header: C:/iConnect/common-files/docroot/WEB-INF/validation-rules/validator-rules.xml,v 1.4 2004/10/14 09:12:03 mcchang Exp $
  $Revision: 1.4 $
  $Date: 2004/10/14 09:12:03 $
   This file contains the default Struts Validator pluggable validator
   definitions.  It should be placed somewhere under /WEB-INF and
   referenced in the struts-config.xml under the plug-in element
   for the ValidatorPlugIn.
      <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
        <set-property property="pathnames" value="/WEB-INF/validator-rules.xml,
                                                  /WEB-INF/validation.xml"/>
      </plug-in>
   These are the default error messages associated with
   each validator defined in this file.  They should be
   added to your projects ApplicationResources.properties
   file or you can associate new ones by modifying the
   pluggable validators msg attributes in this file.
   # Struts Validator Error Messages
   errors.required={0} is required.
   errors.minlength={0} can not be less than {1} characters.
   errors.maxlength={0} can not be greater than {1} characters.
   errors.invalid={0} is invalid.
   errors.byte={0} must be a byte.
   errors.short={0} must be a short.
   errors.integer={0} must be an integer.
   errors.long={0} must be a long.
   errors.float={0} must be a float.
   errors.double={0} must be a double.
   errors.date={0} is not a date.
   errors.range={0} is not in the range {1} through {2}.
   errors.creditcard={0} is an invalid credit card number.
   errors.email={0} is an invalid e-mail address.
   Note: Starting in Struts 1.2.0 the default javascript definitions have
         been consolidated to commons-validator. The default can be overridden
         by supplying a <javascript> element with a CDATA section, just as
         in struts 1.1.
-->
<form-validation>
    <global>
        <validator name="required"
                   classname="org.apache.struts.validator.FieldChecks"
                   method="validateRequired"
                   methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionMessages,
                       javax.servlet.http.HttpServletRequest"
                   msg="errors.required"/>
        <validator name="requiredif"
                   classname="org.apache.struts.validator.FieldChecks"
                   method="validateRequiredIf"
                   methodParams="java.lang.Object,
                               org.apache.commons.validator.ValidatorAction,
                               org.apache.commons.validator.Field,
                               org.apache.struts.action.ActionMessages,
                               org.apache.commons.validator.Validator,
                               javax.servlet.http.HttpServletRequest"
                   msg="errors.required"/>
        <validator name="validwhen"
                   msg="errors.required"
                   classname="org.apache.struts.validator.validwhen.ValidWhen"
                   method="validateValidWhen"
                   methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionMessages,
                       org.apache.commons.validator.Validator,
                       javax.servlet.http.HttpServletRequest"/>
        <validator name="minlength"
                   classname="org.apache.struts.validator.FieldChecks"
                   method="validateMinLength"
                   methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionMessages,
                       javax.servlet.http.HttpServletRequest"
                   depends=""
                   msg="errors.minlength"
                   jsFunction="org.apache.commons.validator.javascript.validateMinLength"/>
        <validator name="maxlength"
                   classname="org.apache.struts.validator.FieldChecks"
                   method="validateMaxLength"
                   methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionMessages,
                       javax.servlet.http.HttpServletRequest"
                   depends=""
                   msg="errors.maxlength"
                   jsFunction="org.apache.commons.validator.javascript.validateMaxLength"/>
        <validator name="mask"
                   classname="org.apache.struts.validator.FieldChecks"
                   method="validateMask"
                   methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionMessages,
                       javax.servlet.http.HttpServletRequest"
                   depends=""
                   msg="errors.invalid"/>
        <validator name="byte"
                   classname="org.apache.struts.validator.FieldChecks"
                   method="validateByte"
                   methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionMessages,
                       javax.servlet.http.HttpServletRequest"
                   depends=""
                   msg="errors.byte"
                   jsFunctionName="ByteValidations"/>
        <validator name="short"
                   classname="org.apache.struts.validator.FieldChecks"
                   method="validateShort"
                   methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionMessages,
                       javax.servlet.http.HttpServletRequest"
                   depends=""
                   msg="errors.short"
                   jsFunctionName="ShortValidations"/>
        <validator name="integer"
                   classname="org.apache.struts.validator.FieldChecks"
                   method="validateInteger"
                   methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionMessages,
                       javax.servlet.http.HttpServletRequest"
                   depends=""
                   msg="errors.integer"
                   jsFunctionName="IntegerValidations"/>
        <validator name="long"
                   classname="org.apache.struts.validator.FieldChecks"
                   method="validateLong"
                   methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionMessages,
                       javax.servlet.http.HttpServletRequest"
                   depends=""
                   msg="errors.long"/>
        <validator name="float"
                   classname="org.apache.struts.validator.FieldChecks"
                   method="validateFloat"
                   methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionMessages,
                       javax.servlet.http.HttpServletRequest"
                   depends=""
                   msg="errors.float"
                   jsFunctionName="FloatValidations"/>
        <validator name="double"
                   classname="org.apache.struts.validator.FieldChecks"
                   method="validateDouble"
                   methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionMessages,
                       javax.servlet.http.HttpServletRequest"
                   depends=""
                   msg="errors.double"/>
        <validator name="date"
                   classname="org.apache.struts.validator.FieldChecks"
                   method="validateDate"
                   methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionMessages,
                       javax.servlet.http.HttpServletRequest"
                   depends=""
                   msg="errors.date"
                   jsFunctionName="DateValidations"/>
        <validator name="intRange"
                   classname="org.apache.struts.validator.FieldChecks"
                   method="validateIntRange"
                   methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionMessages,
                       javax.servlet.http.HttpServletRequest"
                   depends="integer"
                   msg="errors.range"/>
        <validator name="floatRange"
                   classname="org.apache.struts.validator.FieldChecks"
                   method="validateFloatRange"
                   methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionMessages,
                       javax.servlet.http.HttpServletRequest"
                   depends="float"
                   msg="errors.range"/>
        <validator name="creditCard"
                   classname="org.apache.struts.validator.FieldChecks"
                   method="validateCreditCard"
                   methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionMessages,
                       javax.servlet.http.HttpServletRequest"
                   depends=""
                   msg="errors.creditcard"/>
        <validator name="email"
                   classname="org.apache.struts.validator.FieldChecks"
                   method="validateEmail"
                   methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionMessages,
                       javax.servlet.http.HttpServletRequest"
                   depends=""
                   msg="errors.email"/>
        <validator name="url"
                   classname="org.apache.struts.validator.FieldChecks"
                   method="validateUrl"
                   methodParams="java.lang.Object,
                       org.apache.commons.validator.ValidatorAction,
                       org.apache.commons.validator.Field,
                       org.apache.struts.action.ActionMessages,
                       javax.servlet.http.HttpServletRequest"
                   depends=""
                   msg="errors.url"/>
        <!--
          This simply allows struts to include the validateUtilities into a page, it should
          not be used as a validation rule.
        -->
        <validator name="includeJavaScriptUtilities"
                   classname=""
                   method=""
                   methodParams=""
                   depends=""
                   msg=""
                   jsFunction="org.apache.commons.validator.javascript.validateUtilities"/>
        <validator name="twofields"
            classname="com.timeson.framework.util.ValidationUtil"
            method="validateTwoFields"
            methodParams="java.lang.Object,
                          org.apache.commons.validator.ValidatorAction,
                          org.apache.commons.validator.Field,
                          org.apache.struts.action.ActionMessages,
                          javax.servlet.http.HttpServletRequest"
            depends="required"
            msg="errors.twofields">
        <javascript><![CDATA[
            function validateTwoFields(form) {
                var bValid = true;
                var focusField = null;
                var i = 0;
                var fields = new Array();
                var formName = form.getAttributeNode("name");
                oTwoFields = eval('new ' + formName.value + '_twofields()');
                for (x in oTwoFields) {
                    var field = form[oTwoFields[x][0]];
                    var secondField = form[oTwoFields[x][2]("secondProperty")];
                    if (field.type == 'text' ||
                        field.type == 'textarea' ||
                        field.type == 'select-one' ||
                        field.type == 'radio' ||
                        field.type == 'password') {
                        var value;
                        var secondValue;
                        // get field's value
                        if (field.type == "select-one") {
                            var s1i = field.selectedIndex;
                            value = field.options[s1i].value;
                            var s2i = secondField.selectedIndex;
                            secondValue = secondField.options[s2i].value;
                        } else {
                            value = field.value;
                            secondValue = secondField.value;
                        }
                        if (value != secondValue) {
                            if (i == 0) {
                                focusField = field;
                            }
                            fields[i++] = oTwoFields[x][1];
                            bValid = false;
                        }
                    }
                }
                if (fields.length > 0) {
                   focusField.focus();
                   alert(fields.join('\n'));
                }
            return bValid;
        }]]>
        </javascript>
        </validator>

        <constant>
            <constant-name>phone</constant-name>
            <constant-value>^\(?(\d{3,4})\)?[-| ]?(\d{3,4})[-| ]?(\d{4})$</constant-value>
        </constant>
        <constant>
            <constant-name>ip</constant-name>
            <constant-value>
                ^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$</constant-value>
        </constant>
        <constant>
            <constant-name>zip</constant-name>
            <constant-value>^\d{5}\d*$</constant-value>
        </constant>
        <constant>
            <constant-name>currency</constant-name>
            <constant-value>^\d{1,3}(,?\d{1,3})*\.?(\d{1,2})?</constant-value>
        </constant>
        <constant>
            <constant-name>date</constant-name>
            <constant-value>yyyy-MM-dd</constant-value>
        </constant>
        <constant>
            <constant-name>code</constant-name>
            <constant-value>^[a-zA-Z0-9]*$</constant-value>
        </constant>
        <constant>
            <constant-name>days</constant-name>
            <constant-value>^\d{0,7}$</constant-value>
        </constant>
    </global>
</form-validation>

 

 

 

分享到:
评论

相关推荐

    Spring+Struts+Hibernate比较详细的整合配置方案

    2. **Struts整合** - 配置Struts的`struts-config.xml`文件,声明Action和ActionForm,设置Action的Forward规则。 - 创建ActionForm类,如`LoginForm`,定义表单字段,与JSP页面中的表单元素对应。 - 创建Action...

    spring hibernate struts整合

    在Spring和Struts整合时,Spring可以作为Action的依赖注入容器,提供业务对象给Struts,从而减少代码耦合。 4. **整合过程**: - **配置Spring**:创建Spring的配置文件,如`applicationContext.xml`,定义Bean的...

    spring_struts_hibernate整合开发书籍

    书中会详细讲述如何配置这些框架,使它们协同工作,包括Spring与Hibernate的事务管理、数据源配置、以及Struts2与Spring的整合等。 除此之外,书中还可能涵盖了单元测试、异常处理、安全性配置等方面的内容,这些都...

    spring hibernate struts整合开发实例

    【Spring、Hibernate、Struts整合开发】 在Java应用开发中,Spring、Hibernate和Struts是三个非常重要的框架,它们各自负责不同的职责。Spring作为一个轻量级的容器,提供了依赖注入和面向切面编程(AOP)等功能;...

    spring hibernate struts ajax整合项目源代码

    整合的四大框架项目 spring hibernate struts ajax整合项目源代码 spring hibernate struts ajax整合项目源代码

    spring hibernate struts 整合

    整合Spring、Hibernate和Struts,可以创建出高效、模块化且易于维护的企业级Web应用。这个过程通常被称为SSH整合,它是Java开发中的经典组合,尤其是在早期的Java EE项目中非常流行。 首先,Spring作为核心框架,...

    Spring+Struts2+hibernate+Redis整合

    在IT行业中,SSH(Spring、Struts2、Hibernate)是一个经典的Java Web开发框架组合,而Redis则是一个高性能的键值存储系统,常用于缓存和数据持久化。将SSH与Redis整合,可以提升应用程序的性能和响应速度。下面将...

    hibernate struts2 和spring的整合项目

    【标题】:“Hibernate、Struts2与Spring的整合项目” 【描述】:“这是一个将Hibernate、Struts2和Spring三大框架集成在一起的项目示例。它展示了如何在实际开发中有效地结合这三个强大的Java技术,实现数据持久层...

    spring hibernate struts 整合开发所需jar包

    在实际项目中,开发者需要配置相关的XML配置文件,例如Spring的applicationContext.xml,Struts的struts.xml,以及Hibernate的hibernate.cfg.xml。这些配置文件定义了组件的设置、数据源、实体类映射等信息。 整合...

    Struts Spring Hibernate整合实践

    Struts、Spring 和 Hibernate 是三个著名的 Java 开发框架,它们分别负责不同的职责。Struts 是一个 MVC(Model-View-Controller)框架,主要用于构建 web 应用的控制层,简化了Servlet和JSP的开发。Spring 是一个...

    spring hibernate struts2 整合jar包

    标题中的"spring hibernate struts2 整合jar包"指的是一个用于构建Java Web应用程序的集成框架,这个框架集成了Spring、Hibernate和Struts2这三个关键的开源技术。Spring是全面的企业级应用开发框架,提供了依赖注入...

    最新版本的Struts2+Spring4+Hibernate4框架整合

    整合使用最新版本的三大框架(即Struts2、Spring4和Hibernate4),搭建项目架构原型。 项目架构原型:Struts2.3.16 + Spring4.1.1 + Hibernate4.3.6。 此外,还有:log4j、slf4j、junit4、ehcache等知识点。 项目...

    spring整合struts2与hibernate核心配置文件

    整合SSH涉及到的主要配置文件有`struts2-spring-plugin.xml`、`spring-context.xml`以及Hibernate的相关配置文件(如`hibernate.cfg.xml`)。`struts2-spring-plugin.xml`配置Struts2与Spring的集成,确保Action类由...

    SSH整合源码(Struts+Spring+Hibernate整合用户注册例子)

    7. **整合过程**:SSH整合主要包括配置Struts的配置文件(struts-config.xml),Spring的配置文件(spring-beans.xml),以及Hibernate的配置文件(hibernate.cfg.xml)。Struts和Spring之间通过ActionServlet和Spring的...

    spring+hibernate+struts整合jar包

    在本整合中,Spring 2.5.6版本主要作为业务逻辑的管理和协调者,它可以通过配置文件管理Bean的生命周期,同时与Hibernate和Struts进行无缝集成。 Hibernate 3.2是一个流行的ORM(对象关系映射)工具,它消除了...

    struts2 spring hibernate整合的简单登录代码

    Struts2、Spring和Hibernate是Java Web开发中的三大框架,它们各自负责不同的职责:Struts2作为MVC框架处理请求和展示,Spring提供依赖注入和事务管理,Hibernate则作为ORM框架处理数据库操作。将这三个框架整合在...

    struts2+spring+hibernate 整合的jar包

    Struts2、Spring和Hibernate是Java Web开发中的三大框架,它们的整合(SSH)极大地提升了开发效率和项目的可维护性。下面将详细讲解这三大框架的核心功能以及整合过程中的关键知识点。 1. **Struts2**:Struts2是一...

    struts+spring+hibernate整合

    通过以上步骤,一个基本的Struts、Spring和Hibernate整合的应用就搭建完成了。这个整合的关键在于Struts处理HTTP请求,Spring管理业务对象和依赖,而Hibernate则处理数据库操作。这样的架构可以实现松耦合,便于代码...

    spring、struts和hibernate的整合框架

    整合Spring、Struts和Hibernate能带来很多优势,比如松耦合的架构、便捷的数据库操作以及清晰的MVC分离。不过,这种整合也增加了项目的复杂性,因此在实际应用中,需要根据项目需求和团队技术栈来选择合适的技术方案...

Global site tag (gtag.js) - Google Analytics