日系框架之seasar2(S2Struts)---(下)

 validator-rules.xml

<!DOCTYPEform-validationPUBLIC
     "-//ApacheSoftwareFoundation//DTDCommonsValidatorRulesConfiguration1.1.3//EN"
     "http://jakarta.apache.org/commons/dtds/validator_1_1_3.dtd">
<!--
 ThisfilecontainsthedefaultStrutsValidatorpluggablevalidator
 definitions. Itshouldbeplacedsomewhereunder/WEB-INFand
 referencedinthestruts-config.xmlundertheplug-inelement
 fortheValidatorPlugIn.
   <plug-inclassName="org.apache.struts.validator.ValidatorPlugIn">
    <set-propertyproperty="pathnames"value="/WEB-INF/validator-rules.xml,
                         /WEB-INF/validation.xml"/>
   </plug-in>
 Thesearethedefaulterrormessagesassociatedwith
 eachvalidatordefinedinthisfile. Theyshouldbe
 addedtoyourprojectsApplicationResources.properties
 fileoryoucanassociatenewonesbymodifyingthe
 pluggablevalidatorsmsgattributesinthisfile.
 #StrutsValidatorErrorMessages
 errors.required={0}isrequired.
 errors.minlength={0}cannotbelessthan{1}characters.
 errors.maxlength={0}cannotbegreaterthan{1}characters.
 errors.invalid={0}isinvalid.
 errors.byte={0}mustbeabyte.
 errors.short={0}mustbeashort.
 errors.integer={0}mustbeaninteger.
 errors.long={0}mustbealong.
 errors.float={0}mustbeafloat.
 errors.double={0}mustbeadouble.
 errors.date={0}isnotadate.
 errors.range={0}isnotintherange{1}through{2}.
 errors.creditcard={0}isaninvalidcreditcardnumber.
 errors.email={0}isaninvalide-mailaddress.
 errors.url={0}isaninvalidurl(webaddress).
 errors.minbytelength={0}cannotbelessthan{1}bytes.
 errors.maxbytelength={0}cannotbegreaterthan{1}bytes.
 Note:StartinginStruts1.2.0thedefaultjavascriptdefinitionshave
    beenconsolidatedtocommons-validator.Thedefaultcanbeoverridden
    bysupplyinga<javascript>elementwithaCDATAsection,justas
    instruts1.1.
-->
<form-validation>
 <global>
   <validatorname="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,
           org.apache.commons.validator.Validator,
           javax.servlet.http.HttpServletRequest"
         msg="errors.required"/>
   <validatorname="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"/>
   <validatorname="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"/>
   <validatorname="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,
           org.apache.commons.validator.Validator,
           javax.servlet.http.HttpServletRequest"
       depends=""
         msg="errors.minlength"
     jsFunction="org.apache.commons.validator.javascript.validateMinLength"/>
   <validatorname="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,
           org.apache.commons.validator.Validator,
           javax.servlet.http.HttpServletRequest"
       depends=""
         msg="errors.maxlength"
     jsFunction="org.apache.commons.validator.javascript.validateMaxLength"/>
   <validatorname="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,
           org.apache.commons.validator.Validator,
           javax.servlet.http.HttpServletRequest"
       depends=""
         msg="errors.invalid"/>
   <validatorname="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,
           org.apache.commons.validator.Validator,
           javax.servlet.http.HttpServletRequest"
       depends=""
         msg="errors.byte"
   jsFunctionName="ByteValidations"/>
   <validatorname="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,
           org.apache.commons.validator.Validator,
           javax.servlet.http.HttpServletRequest"
       depends=""
         msg="errors.short"
   jsFunctionName="ShortValidations"/>
   <validatorname="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,
           org.apache.commons.validator.Validator,
           javax.servlet.http.HttpServletRequest"
       depends=""
         msg="errors.integer"
   jsFunctionName="IntegerValidations"/>
   <validatorname="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,
           org.apache.commons.validator.Validator,
           javax.servlet.http.HttpServletRequest"
       depends=""
         msg="errors.long"/>
   <validatorname="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,
           org.apache.commons.validator.Validator,
           javax.servlet.http.HttpServletRequest"
       depends=""
         msg="errors.float"
   jsFunctionName="FloatValidations"/>
   <validatorname="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,
           org.apache.commons.validator.Validator,
           javax.servlet.http.HttpServletRequest"
       depends=""
         msg="errors.double"/>
   <validatorname="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,
           org.apache.commons.validator.Validator,
           javax.servlet.http.HttpServletRequest"
       depends=""
         msg="errors.date"
   jsFunctionName="DateValidations"/>
   <validatorname="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,
           org.apache.commons.validator.Validator,
           javax.servlet.http.HttpServletRequest"
       depends="integer"
         msg="errors.range"/>
   <validatorname="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,
           org.apache.commons.validator.Validator,
           javax.servlet.http.HttpServletRequest"
       depends="float"
         msg="errors.range"/>
   <validatorname="doubleRange"
      classname="org.apache.struts.validator.FieldChecks"
       method="validateDoubleRange"
    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"
       depends="double"
         msg="errors.range"/>
   <validatorname="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,
           org.apache.commons.validator.Validator,
           javax.servlet.http.HttpServletRequest"
       depends=""
         msg="errors.creditcard"/>
   <validatorname="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,
           org.apache.commons.validator.Validator,
           javax.servlet.http.HttpServletRequest"
       depends=""
         msg="errors.email"/>
   <validatorname="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,
           org.apache.commons.validator.Validator,
           javax.servlet.http.HttpServletRequest"
       depends=""
         msg="errors.url"/>
   <validatorname="minbytelength"
      classname="org.seasar.struts.validator.FieldChecks"
       method="validateMinByteLength"
    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"
       depends=""
         msg="errors.minbytelength"/>
   <validatorname="maxbytelength"
      classname="org.seasar.struts.validator.FieldChecks"
       method="validateMaxByteLength"
    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"
       depends=""
         msg="errors.maxbytelength"/>
  <!--
   ThissimplyallowsstrutstoincludethevalidateUtilitiesintoapage,itshould
   notbeusedasavalidationrule.
  -->
  <validatorname="includeJavaScriptUtilities"
      classname=""
       method=""
    methodParams=""
       depends=""
         msg=""
     jsFunction="org.apache.commons.validator.javascript.validateUtilities"/>
 </global>
</form-validation>

 

 

web.xml

<?xmlversion="1.0"encoding="ISO-8859-1"?>
<!DOCTYPEweb-app
  PUBLIC"-//SunMicrosystems,Inc.//DTDWebApplication2.3//EN"
  "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
 <display-name>StrutsApplication</display-name>
 <filter>
  <filter-name>s2filter</filter-name>
  <filter-class>org.seasar.framework.container.filter.S2ContainerFilter</filter-class>
 </filter>
 <filter>
  <filter-name>s2strutsfilter</filter-name>
  <filter-class>org.seasar.struts.filter.S2StrutsFilter</filter-class>
 </filter>
 <filter>
  <filter-name>encodingfilter</filter-name>
  <filter-class>org.seasar.extension.filter.EncodingFilter</filter-class>
  <init-param>
   <param-name>encoding</param-name>
   <param-value>Windows-31j</param-value>
  </init-param>
 </filter>
 <filter-mapping>
  <filter-name>s2filter</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>
 <filter-mapping>
  <filter-name>s2strutsfilter</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>
 <filter-mapping>
  <filter-name>encodingfilter</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>
 <servlet>
  <servlet-name>s2container</servlet-name>
  <servlet-class>org.seasar.framework.container.servlet.S2ContainerServlet</servlet-class>
  <load-on-startup>1</load-on-startup>
 </servlet>
 <!--StandardActionServletConfiguration(withdebugging)-->
 <servlet>
  <servlet-name>action</servlet-name>
  <servlet-class>org.seasar.struts.servlet.S2ActionServlet</servlet-class>
  <init-param>
   <param-name>config</param-name>
   <param-value>/WEB-INF/struts-config.xml</param-value>
  </init-param>
  <init-param>
   <param-name>debug</param-name>
   <param-value>2</param-value>
  </init-param>
  <init-param>
   <param-name>detail</param-name>
   <param-value>2</param-value>
  </init-param>
  <load-on-startup>2</load-on-startup>
 </servlet>
 <servlet>
  <servlet-name>MayaaServlet</servlet-name>
  <servlet-class>org.seasar.mayaa.impl.MayaaServlet</servlet-class>
  <load-on-startup>3</load-on-startup>
 </servlet>
 <servlet-mapping>
  <servlet-name>s2container</servlet-name>
  <url-pattern>/s2container</url-pattern>
 </servlet-mapping>
 <!--StandardActionServletMapping-->
 <servlet-mapping>
  <servlet-name>action</servlet-name>
  <url-pattern>*.do</url-pattern>
 </servlet-mapping>
 <servlet-mapping>
  <servlet-name>MayaaServlet</servlet-name>
  <url-pattern>*.html</url-pattern>
 </servlet-mapping>
 <!--TheUsualWelcomeFileList-->
 <welcome-file-list>
  <welcome-file>index.html</welcome-file>
  <welcome-file>index.jsp</welcome-file>
 </welcome-file-list>
</web-app>

 

 

 debug.js

/*settrue/false*/
vardebug=true;
if(debug){
  load("dump.js");
}

  default.mayaa

<?xmlversion="1.0"encoding="UTF-8"?>
<m:mayaaxmlns:m="http://mayaa.seasar.org">
  <m:beforeRender><![CDATA[
    varcontextPath=request.getContextPath();
    varprintln=function(value){
      if(value!=null){
        java.lang.System.out.println(value);
      }else{
        java.lang.System.out.println(""+value);
      }
    };
    load("debug.js");
  ]]></m:beforeRender>
</m:mayaa>

  dump.js

functionprintAttribute(req){
  varnames=req.getAttributeNames();
  while(names.hasMoreElements()){
    varname=names.nextElement();
    print("att:"+name+"="+req.getAttribute(name));
  }
}
functionprintParameter(req){
  varnames=req.getParameterNames();
  while(names.hasMoreElements()){
    varname=names.nextElement();
    print("prm:"+name+"="+req.getParameter(name));
  }
}
functionprintSession(session){
  varnames=session.getAttributeNames();
  while(names.hasMoreElements()){
    varname=names.nextElement();
    print("ses:"+name+"="+session.getAttribute(name));
  }
}
functionprint(value){
  java.lang.System.out.println(""+value);
}
varreq=request.getUnderlyingContext();
print("------req-path:"+request.getRequestedPath());
printParameter(req);
printAttribute(req);
printSession(req.getSession());

 

  index.html

<!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.0Transitional//EN">
<html>
<head>
 <linkhref="../../css/global.css"rel="stylesheet"type="text/css"></link>
 <scripttype="text/javascript"src="../../js/execute.js"></script>
 <titleid="pageTitle">
  S2StrutsSampleCalculateApplicationDemo
 </title> 
</head>
<body>
<divid="appBody">
</div>
</body>
</html>

  index.mayaa

<?xmlversion="1.0"encoding="Shift_JIS"?>
<m:mayaaxmlns:m="http://mayaa.seasar.org" 
    xmlns:bean="http://struts.apache.org/tags-bean"
    m:noCache="true"
    m:extends="/pages/layout/layout.html">
  <m:doRenderid="pageTitle"name="title">
    <bean:messagekey="sample.title"/>
  </m:doRender>
  <m:doRenderid="appBody"name="content"/>
</m:mayaa>

你可能感兴趣的:(JavaScript,apache,框架,servlet,struts)