如何扩充struts验证框架,进行多表单页面的验证

纯前端实现的 JSON / YAML / CSV 互转工具技术实现 本文介绍了一款纯前端的JSON/YAML/CSV格式互转工具,基于原生JavaScript与js-yaml、PapaParse库实现,支持三者全向转换。所有操作在浏览器本地完成,无需上传数据,保障隐私安全。工具具备实时大小统计、错误提示、一键复制、文件下载及深色/浅色主题切换等功能,适用于配置管理、数据导出等场景,免费无注册,可离线使用。 阅读详情

struts的validator的客户端验证,不能进行多表单页面的验证,原因是由<html:script>标签生成的javascipt是根据每个表单,生成一段代码。例如:

<html:javascript formName="searchSgbySjForm" dynamicJavascript="true" staticJavascript="false"/>生成
     var bCancel = false;

    function validateSearchSgbySjForm(form) {                                                                  
        if (bCancel)
      return true;
        else
       return validateRequired(form) && validateDate(form);
   }

    function required () {
     this.aa = new Array("sgfssjq", "事故发生时间起 不可为空.", new Function ("varName", "this.datePatternStrict='yyy-MM-dd';  return this[varName];"));
     this.ab = new Array("sgfssjz", "事故发生时间止 不可为空.", new Function ("varName", "this.datePatternStrict='yyy-MM-dd';  return this[varName];"));
    }

    function DateValidations () {
     this.aa = new Array("sgfssjq", "事故发生时间起 不是有效的日期类型.", new Function ("varName", "this.datePatternStrict='yyy-MM-dd';  return this[varName];"));
     this.ab = new Array("sgfssjz", "事故发生时间止 不是有效的日期类型.", new Function ("varName", "this.datePatternStrict='yyy-MM-dd';  return this[varName];"));
    }

如果有多个的话required和DateValidations 都会重复的,而javascript是只认最后一个函数的。所以,会导致验证出错。

再写一个标签 ,主要根据原来的代码修改,代码如下:

/*
 * $Header: /home/cvs/jakarta-struts/src/share/org/apache/struts/taglib/html/JavascriptValidatorTag.java,v 1.52 2004/08/07 04:17:52 martinc Exp $
 * $Revision: 1.52 $
 * $Date: 2004/08/07 04:17:52 $
 *
 * Copyright 2001-2004 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.tmri.acd.tag;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.BodyTagSupport;

import org.apache.commons.validator.Field;
import org.apache.commons.validator.Form;
import org.apache.commons.validator.ValidatorAction;
import org.apache.commons.validator.ValidatorResources;
import org.apache.commons.validator.util.ValidatorUtils;
import org.apache.commons.validator.Var;
import org.apache.struts.Globals;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.config.ModuleConfig;
import com.tmri.acd.tag.TagUtils;
import org.apache.struts.util.MessageResources;
import org.apache.struts.validator.Resources;
import org.apache.struts.validator.ValidatorPlugIn;
import java.util.StringTokenizer;

/**
 * Custom tag that generates JavaScript for client side validation based
 * on the validation rules loaded by the <code>ValidatorPlugIn</code>
 * defined in the struts-config.xml file.
 *
 * @version $Revision: 1.52 $ $Date: 2004/08/07 04:17:52 $
 * @since Struts 1.1
 */
public class JavascriptValidatorTag extends BodyTagSupport {

    /**
     * A Comparator to use when sorting ValidatorAction objects.
     */
    private static final Comparator actionComparator = new Comparator() {
        public int compare(Object o1, Object o2) {

            ValidatorAction va1 = (ValidatorAction) o1;
            ValidatorAction va2 = (ValidatorAction) o2;

            if ((va1.getDepends() == null || va1.getDepends().length() == 0)
                && (va2.getDepends() == null || va2.getDepends().length() == 0)) {
                return 0;

            } else if (
                (va1.getDepends() != null && va1.getDepends().length() > 0)
                    && (va2.getDepends() == null || va2.getDepends().length() == 0)) {
                return 1;

            } else if (
                (va1.getDepends() == null || va1.getDepends().length() == 0)
                    && (va2.getDepends() != null && va2.getDepends().length() > 0)) {
                return -1;

            } else {
                return va1.getDependencyList().size() - va2.getDependencyList().size();
            }
        }
    };

    /**
     * The start of the HTML comment hiding JavaScript from old browsers.
     * @since Struts 1.2
     */
    protected static final String HTML_BEGIN_COMMENT = "/n<!-- Begin /n";

    /**
     * The end of the HTML comment hiding JavaScript from old browsers.
     * @since Struts 1.2
     */
    protected static final String HTML_END_COMMENT = "//End --> /n";

    // ----------------------------------------------------------- Properties

    /**
     * The servlet context attribute key for our resources.
     */
    protected String bundle = Globals.MESSAGES_KEY;

    /**
     * The default locale on our server.
     * @deprecated This variable is no longer used.
     */
    protected static Locale defaultLocale = Locale.getDefault();

    /**
     * The name of the form that corresponds with the action name
     * in struts-config.xml. Specifying a form name places a
     * &lt;script&gt; &lt;/script&gt; around the javascript.
     */
    protected String formName = null;

    /**
     * formName is used for both Javascript and non-javascript validations.
     * For the javascript validations, there is the possibility that we will
     * be rewriting the formName (if it is a ValidatorActionForm instead of just
     * a ValidatorForm) so we need another variable to hold the formName just for
     * javascript usage.
     */
    protected String jsFormName = null;

    /**
     * The line ending string.
     */
    protected static String lineEnd = System.getProperty("line.separator");

    /**
     * The current page number of a multi-part form.
     * Only valid when the formName attribute is set.
     */
    protected int page = 0;

    /**
     * This will be used as is for the JavaScript validation method name if it has a value.  This is
     * the method name of the main JavaScript method that the form calls to perform validations.
     */
    protected String methodName = null;

    /**
     * Include language attribute in the &lt;script&gt; element.  This property is
     * ignored in XHTML mode.
     * @since Struts 1.2
     */
    protected boolean scriptLanguage = true;

    /**
     * The static JavaScript methods will only be printed if this is set to "true".
     */
    protected String staticJavascript = "true";

    /**
     * The dynamic JavaScript objects will only be generated if this is set to "true".
     */
    protected String dynamicJavascript = "true";

    /**
     * The src attribute for html script element (used to include an external script
     * resource). The src attribute is only recognized
     * when the formName attribute is specified.
     */
    protected String src = null;

    /**
     * The JavaScript methods will enclosed with html comments if this is set to "true".
     */
    protected String htmlComment = "true";

    /**
     * Hide JavaScript methods in a CDATA section for XHTML when "true".
     */
    protected String cdata = "true";

    /**
     * Gets the key (form name) that will be used
     * to retrieve a set of validation rules to be
     * performed on the bean passed in for validation.
     */
    public String getFormName() {
        return formName;
    }

    /**
     * Sets the key (form name) that will be used
     * to retrieve a set of validation rules to be
     * performed on the bean passed in for validation.
     * Specifying a form name places a
     * &lt;script&gt; &lt;/script&gt; tag around the javascript.
     */
    public void setFormName(String formName) {
        this.formName = formName;
    }

    /**
     * @return Returns the jsFormName.
     */
    public String getJsFormName() {
        return jsFormName;
    }
    /**
     * @param jsFormName The jsFormName to set.
     */
    public void setJsFormName(String jsFormName) {
        this.jsFormName = jsFormName;
    }
    /**
     * Gets the current page number of a multi-part form.
     * Only field validations with a matching page numer
     * will be generated that match the current page number.
     * Only valid when the formName attribute is set.
     */
    public int getPage() {
        return page;
    }

    /**
     * Sets the current page number of a multi-part form.
     * Only field validations with a matching page numer
     * will be generated that match the current page number.
     * Only valid when the formName attribute is set.
     */
    public void setPage(int page) {
        this.page = page;
    }

    /**
     * Gets the method name that will be used for the Javascript
     * validation method name if it has a value.  This overrides
     * the auto-generated method name based on the key (form name)
     * passed in.
     */
    public String getMethod() {
        return methodName;
    }

    /**
     * Sets the method name that will be used for the Javascript
     * validation method name if it has a value.  This overrides
     * the auto-generated method name based on the key (form name)
     * passed in.
     */
    public void setMethod(String methodName) {
        this.methodName = methodName;
    }

    /**
     * Gets whether or not to generate the static
     * JavaScript.  If this is set to 'true', which
     * is the default, the static JavaScript will be generated.
     */
    public String getStaticJavascript() {
        return staticJavascript;
    }

    /**
     * Sets whether or not to generate the static
     * JavaScript.  If this is set to 'true', which
     * is the default, the static JavaScript will be generated.
     */
    public void setStaticJavascript(String staticJavascript) {
        this.staticJavascript = staticJavascript;
    }

    /**
     * Gets whether or not to generate the dynamic
     * JavaScript.  If this is set to 'true', which
     * is the default, the dynamic JavaScript will be generated.
     */
    public String getDynamicJavascript() {
        return dynamicJavascript;
    }

    /**
     * Sets whether or not to generate the dynamic
     * JavaScript.  If this is set to 'true', which
     * is the default, the dynamic JavaScript will be generated.
     */
    public void setDynamicJavascript(String dynamicJavascript) {
        this.dynamicJavascript = dynamicJavascript;
    }

    /**
      * Gets whether or not to delimit the
      * JavaScript with html comments.  If this is set to 'true', which
      * is the default, the htmlComment will be surround the JavaScript.
      */
    public String getHtmlComment() {
        return htmlComment;
    }

    /**
     * Sets whether or not to delimit the
     * JavaScript with html comments.  If this is set to 'true', which
     * is the default, the htmlComment will be surround the JavaScript.
     */
    public void setHtmlComment(String htmlComment) {
        this.htmlComment = htmlComment;
    }

    /**
     * Gets the src attribute's value when defining
     * the html script element.
     */
    public String getSrc() {
        return src;
    }

    /**
     * Sets the src attribute's value when defining
     * the html script element. The src attribute is only recognized
     * when the formName attribute is specified.
     */
    public void setSrc(String src) {
        this.src = src;
    }

    /**
     * Render the JavaScript for to perform validations based on the form name.
     *
     * @exception JspException if a JSP exception has occurred
     */
    public int doStartTag() throws JspException {

        JspWriter writer = pageContext.getOut();
        try {
            writer.print(this.renderJavascript());

        } catch (IOException e) {
            throw new JspException(e.getMessage());
        }

        return EVAL_BODY_TAG;

    }

    /**
     * Returns fully rendered JavaScript.
     * @since Struts 1.2
     */
    protected String renderJavascript() throws JspException {
        StringBuffer results = new StringBuffer();

        ModuleConfig config = TagUtils.getInstance().getModuleConfig(pageContext);
        ValidatorResources resources =
            (ValidatorResources) pageContext.getAttribute(
                ValidatorPlugIn.VALIDATOR_KEY + config.getPrefix(),
                PageContext.APPLICATION_SCOPE);

        Locale locale = TagUtils.getInstance().getUserLocale(this.pageContext, null);

        Form form = resources.getForm(locale, formName);

        if ("true".equalsIgnoreCase(dynamicJavascript) && form == null)
        {
            throw new JspException("No form found under '"
                                   + formName
                                   + "' in locale '"
                                   + locale
                                   + "'");
        }

        if (form != null) {
            if ("true".equalsIgnoreCase(dynamicJavascript)) {
                results.append(
                        this.createDynamicJavascript(config, resources, locale, form));

            } else if ("true".equalsIgnoreCase(staticJavascript)) {
                results.append(this.renderStartElement());
                if ("true".equalsIgnoreCase(htmlComment)) {
                    results.append(HTML_BEGIN_COMMENT);
                }
            }
        }

        if ("true".equalsIgnoreCase(staticJavascript)) {
            results.append(getJavascriptStaticMethods(resources));
        }

        if (form != null
            && ("true".equalsIgnoreCase(dynamicJavascript)
                || "true".equalsIgnoreCase(staticJavascript))) {

            results.append(getJavascriptEnd());
        }

        return results.toString();
    }

    /**
     * Generates the dynamic JavaScript for the form.
     * @param config
     * @param resources
     * @param locale
     * @param form
     */
    private String createDynamicJavascript(
        ModuleConfig config,
        ValidatorResources resources,
        Locale locale,
        Form form) throws JspException {

        StringBuffer results = new StringBuffer();

        MessageResources messages =
            (MessageResources) pageContext.getAttribute(
                bundle + config.getPrefix(),
                PageContext.APPLICATION_SCOPE);
        //获取验证
        List actions = this.createActionList(resources, form);

        final String methods = this.createMethods(actions, this.stopOnError(config));

        String formName = form.getName();
        jsFormName = formName;
                if(jsFormName.charAt(0) == '/') {
                    String mappingName = TagUtils.getInstance().getActionMappingName(jsFormName);
                    ActionMapping mapping = (ActionMapping) config.findActionConfig(mappingName);
                    if (mapping == null) {
                        JspException e = new JspException(messages.getMessage("formTag.mapping", mappingName));
                        pageContext.setAttribute(Globals.EXCEPTION_KEY, e, PageContext.REQUEST_SCOPE);
                        throw e;
                    }
                    jsFormName = mapping.getAttribute();
                }
        //验证输出
        results.append(this.getJavascriptBegin(methods));
        results.append("        {   /n");
        for (Iterator i = actions.iterator(); i.hasNext();) {
            ValidatorAction va = (ValidatorAction) i.next();
            int jscriptVar = 0;
            String functionName = null;


            if (va.getJsFunctionName() != null
                && va.getJsFunctionName().length() > 0) {
                functionName = va.getJsFunctionName();
            } else {
                functionName = va.getName();
            }

            //输出函数
            results.append("         function " +  functionName + " () { /n");
//            results.append("    function " +  functionName + " () { /n");
            for (Iterator x = form.getFields().iterator(); x.hasNext();) {
                Field field = (Field) x.next();

                // Skip indexed fields for now until there is a good way to handle
                // error messages (and the length of the list (could retrieve from scope?))
                if (field.isIndexed()
                    || field.getPage() != page
                    || !field.isDependency(va.getName())) {

                    continue;
                }

                String message = Resources.getMessage(messages, locale, va, field);

                message = (message != null) ? message : "";

                // prefix variable with 'a' to make it a legal identifier
                results.append(
                    "         this.a"
                        + jscriptVar++
                        + " = new Array(/""
                        + field.getKey()
                        + "/", /""
                        + escapeQuotes(message)
                        + "/", ");

                results.append("new Function (/"varName/", /"");

                Map vars = field.getVars();
                // Loop through the field's variables.
                Iterator varsIterator = vars.keySet().iterator();
                while (varsIterator.hasNext()) {
                    String varName = (String) varsIterator.next();
                    Var var = (Var) vars.get(varName);
                    String varValue = var.getValue();
                    String jsType = var.getJsType();

                    // skip requiredif variables field, fieldIndexed, fieldTest, fieldValue
                    if (varName.startsWith("field")) {
                        continue;
                    }

                    if (Var.JSTYPE_INT.equalsIgnoreCase(jsType)) {
                        results.append(
                            "this."
                                + varName
                                + "="
                                + ValidatorUtils.replace(varValue, "//", "////")
                                + "; ");
                    } else if (Var.JSTYPE_REGEXP.equalsIgnoreCase(jsType)) {
                        results.append(
                            "this."
                                + varName
                                + "=/"
                                + ValidatorUtils.replace(varValue, "//", "////")
                                + "/; ");
                    } else if (Var.JSTYPE_STRING.equalsIgnoreCase(jsType)) {
                        results.append(
                            "this."
                                + varName
                                + "='"
                                + ValidatorUtils.replace(varValue, "//", "////")
                                + "'; ");
                        // So everyone using the latest format doesn't need to change their xml files immediately.
                    } else if ("mask".equalsIgnoreCase(varName)) {
                        results.append(
                            "this."
                                + varName
                                + "=/"
                                + ValidatorUtils.replace(varValue, "//", "////")
                                + "/; ");
                    } else {
                        results.append(
                            "this."
                                + varName
                                + "='"
                                + ValidatorUtils.replace(varValue, "//", "////")
                                + "'; ");
                    }
                }

                results.append(" return this[varName];/"));/n");
            }
            results.append("          } /n/n");
            results.append( "         " + functionName + "= new " + functionName + "();/n");
        }
        //long 修改
        results.append("         var formValidationResult;/n");

        results.append("         formValidationResult = " + methods + "; /n");
        results.append("         return (formValidationResult == 1);/n        }/n ");

        results.append("   } /n/n");
        return results.toString();
    }

    private String escapeQuotes(String in)
    {
        if (in == null || in.indexOf("/"") == -1)
        {
            return in;
        }
        StringBuffer buffer = new StringBuffer();
        StringTokenizer tokenizer = new StringTokenizer(in, "/"", true);

        while (tokenizer.hasMoreTokens())
        {
            String token = tokenizer.nextToken();
            if (token.equals("/""))
            {
                buffer.append("//");
            }
            buffer.append(token);
        }

        return buffer.toString();
    }

    /**
     * Determines if validations should stop on an error.
     * @param config The <code>ModuleConfig</code> used to lookup the
     * stopOnError setting.
     * @return <code>true</code> if validations should stop on errors.
     */
    private boolean stopOnError(ModuleConfig config) {
        Object stopOnErrorObj =
            pageContext.getAttribute(
                ValidatorPlugIn.STOP_ON_ERROR_KEY + '.' + config.getPrefix(),
                PageContext.APPLICATION_SCOPE);

        boolean stopOnError = true;

        if (stopOnErrorObj instanceof Boolean) {
            stopOnError = ((Boolean) stopOnErrorObj).booleanValue();
        }

        return stopOnError;
    }

    /**
     * Creates the JavaScript methods list from the given actions.
     * @param actions A List of ValidatorAction objects.
     * @param stopOnError If true, behaves like released version of struts 1.1
     *        and stops after first error. If false, evaluates all validations.
     * @return JavaScript methods.
     */
    private String createMethods(List actions, boolean stopOnError) {
        StringBuffer methods = new StringBuffer();
        final String methodOperator = stopOnError ? " && " : " & ";

        Iterator iter = actions.iterator();
        while (iter.hasNext()) {
            ValidatorAction va = (ValidatorAction) iter.next();

            if (methods.length() > 0) {
                methods.append(methodOperator);
            }
            //LONG修改
            String strMethod = va.getMethod();
            if (va.getJsFunctionName() != null
                && va.getJsFunctionName().length() > 0) {
                strMethod = va.getJsFunctionName();
            } else {
                strMethod = va.getName();
            }

            methods.append(va.getMethod())
                   .append("(form," + strMethod + ")");
        }

        return methods.toString();
    }

    /**
     * Get List of actions for the given Form.
     * @param resources
     * @param form
     * @return A sorted List of ValidatorAction objects.
     */
    private List createActionList(ValidatorResources resources, Form form) {

        List actionMethods = new ArrayList();

        Iterator iterator = form.getFields().iterator();
        while (iterator.hasNext()) {
            Field field = (Field) iterator.next();

            for (Iterator x = field.getDependencyList().iterator(); x.hasNext();) {
                Object o = x.next();

                if (o != null && !actionMethods.contains(o)) {
                    actionMethods.add(o);
                }
            }
        }

        List actions = new ArrayList();

        // Create list of ValidatorActions based on actionMethods
        iterator = actionMethods.iterator();
        while (iterator.hasNext()) {
            String depends = (String) iterator.next();
            ValidatorAction va = resources.getValidatorAction(depends);

            // throw nicer NPE for easier debugging
            if (va == null) {
                throw new NullPointerException(
                    "Depends string /""
                        + depends
                        + "/" was not found in validator-rules.xml.");
            }

            if (va.getJavascript() != null && va.getJavascript().length() > 0) {
                actions.add(va);
            } else {
                iterator.remove();
            }
        }

        Collections.sort(actions, actionComparator);

        return actions;
    }

    /**
     * Release any acquired resources.
     */
    public void release() {
        super.release();
        bundle = Globals.MESSAGES_KEY;
        formName = null;
        jsFormName = null;
        page = 0;
        methodName = null;
        staticJavascript = "true";
        dynamicJavascript = "true";
        htmlComment = "true";
        cdata = "true";
        src = null;
    }

    /**
     * Returns the opening script element and some initial javascript.
     */
    protected String getJavascriptBegin(String methods) {
        StringBuffer sb = new StringBuffer();
        String name = jsFormName.replace('/', '_'); // remove any '/' characters
        name =
            jsFormName.substring(0, 1).toUpperCase()
                + jsFormName.substring(1, jsFormName.length());

        sb.append(this.renderStartElement());

        if (this.isXhtml() && "true".equalsIgnoreCase(this.cdata)) {
            sb.append("<![CDATA[/r/n");
        }

        if (!this.isXhtml() && "true".equals(htmlComment)) {
            sb.append(HTML_BEGIN_COMMENT);
        }
//        sb.append("/n     var bCancel = false; /n/n");

        if (methodName == null || methodName.length() == 0) {
            sb.append(
                "    function validate"
                    + name
                    + "(form) {                                                                   /n");
        } else {
            sb.append(
                "    function "
                    + methodName
                    + "(form) {                                                                   /n");
        }
        sb.append("/n     var bCancel = false; /n/n");
        sb.append("        if (bCancel) /n");
        sb.append("      return true; /n");
        sb.append("        else /n");

        // Always return true if there aren't any Javascript validation methods
        if (methods == null || methods.length() == 0) {
            sb.append("       return true; /n");
        } else {
            //Making Sure that Bitwise operator works:
        }

//        sb.append("   } /n/n");

        return sb.toString();
    }

    protected String getJavascriptStaticMethods(ValidatorResources resources) {
        StringBuffer sb = new StringBuffer();

        sb.append("/n/n");

        Iterator actions = resources.getValidatorActions().values().iterator();
        while (actions.hasNext()) {
            ValidatorAction va = (ValidatorAction) actions.next();
            if (va != null) {
                String javascript = va.getJavascript();
                if (javascript != null && javascript.length() > 0) {
                    sb.append(javascript + "/n");
                }
            }
        }

        return sb.toString();
    }

    /**
     * Returns the closing script element.
     */
    protected String getJavascriptEnd() {
        StringBuffer sb = new StringBuffer();

        sb.append("/n");
        if (!this.isXhtml() && "true".equals(htmlComment)){
            sb.append(HTML_END_COMMENT);
        }

        if (this.isXhtml() && "true".equalsIgnoreCase(this.cdata)) {
            sb.append("]]>/r/n");
        }

        sb.append("</script>/n/n");

        return sb.toString();
    }

    /**
     * Constructs the beginning &lt;script&gt; element depending on XHTML
     * status.
     * @since Struts 1.2
     */
    protected String renderStartElement() {
        StringBuffer start = new StringBuffer("<script type=/"text/javascript/"");

        // there is no language attribute in XHTML
        if (!this.isXhtml() && this.scriptLanguage) {
            start.append(" language=/"Javascript1.1/"");
        }

        if (this.src != null) {
            start.append(" src=/"" + src + "/"");
        }

        start.append("> /n");
        return start.toString();
    }

    /**
     * Returns true if this is an xhtml page.
     */
    private boolean isXhtml() {
        return TagUtils.getInstance().isXhtml(this.pageContext);
    }

    /**
     * Returns the cdata setting "true" or "false".
     * @return String - "true" if JavaScript will be hidden in a CDATA section
     */
    public String getCdata() {
        return cdata;
    }

    /**
     * Sets the cdata status.
     * @param cdata The cdata to set
     */
    public void setCdata(String cdata) {
        this.cdata = cdata;
    }

    /**
     * Gets whether or not the &lt;script&gt; element will include the
     * language attribute.
     * @return true if language attribute will be included.
     * @since Struts 1.2
     */
    public boolean getScriptLanguage() {
        return this.scriptLanguage;
    }

    /**
     * Sets whether or not the &lt;script&gt; element will include the
     * language attribute.
     * @since Struts 1.2
     */
    public void setScriptLanguage(boolean scriptLanguage) {
        this.scriptLanguage = scriptLanguage;
    }

}

客户端如下引用:

<html:javascript1 formName="searchSgbySjForm" dynamicJavascript="true" staticJavascript="false"/>

生成代码如下:

    function validateSearchSgbySjForm(form) {                                                                  

     var bCancel = false;

        if (bCancel)
      return true;
        else
        {  
         function required () {
         this.a0 = new Array("sgfssjq", "事故发生时间起 不可为空.", new Function ("varName", "this.datePatternStrict='yyy-MM-dd';  return this[varName];"));
         this.a1 = new Array("sgfssjz", "事故发生时间止 不可为空.", new Function ("varName", "this.datePatternStrict='yyy-MM-dd';  return this[varName];"));
          }

         required= new required();
         function DateValidations () {
         this.a0 = new Array("sgfssjq", "事故发生时间起 不是有效的日期类型.", new Function ("varName", "this.datePatternStrict='yyy-MM-dd';  return this[varName];"));
         this.a1 = new Array("sgfssjz", "事故发生时间止 不是有效的日期类型.", new Function ("varName", "this.datePatternStrict='yyy-MM-dd';  return this[varName];"));
          }

         DateValidations= new DateValidations();
         var formValidationResult;
         formValidationResult = validateRequired(form,required) && validateDate(form,DateValidations);
         return (formValidationResult == 1);
        }
    }

可见DateValidations和required作为子函数,所以不会重复。

最后,修改静态js文件,主要增加了传入数组的功能,加入如下:

            function validateRequired(form,oRequired) {
                var isValid = true;
                var focusField = null;
                var i = 0;
                var fields = new Array();
//                oRequired = new fun();
                for (x in oRequired) {
                 var field = form[oRequired[x][0]];
                    if (field.type == 'text' ||
                        field.type == 'textarea' ||
                        field.type == 'file' ||
                        field.type == 'select-one' ||
                        field.type == 'radio' ||
                        field.type == 'password') {

                        var value = '';
      // get field's value
      if (field.type == "select-one") {
       var si = field.selectedIndex;
       if (si >= 0) {
        value = field.options[si].value;
       }
      } else {
       value = field.value;
      }
                        if (value == "") {

                         if (i == 0) {
                             focusField = field;
                         }
                         fields[i++] = oRequired[x][1];
                         isValid = false;
                        }
                    }
                }
                if (fields.length > 0) {
                   focusField.focus();
                   alert(fields.join('/n'));
                }
                return isValid;
            }

            function validateMinLength(form,oMinLength) {
                var isValid = true;
                var focusField = null;
                var i = 0;
                var fields = new Array();
//                oMinLength = new minlength();
                for (x in oMinLength) {
                    var field = form[oMinLength[x][0]];

                    if (field.type == 'text' ||
                        field.type == 'textarea') {

                        var iMin = parseInt(oMinLength[x][2]("minlength"));
                        if ((trim(field.value).length > 0) && (field.value.length < iMin)) {
                            if (i == 0) {
                                focusField = field;
                            }
                            fields[i++] = oMinLength[x][1];
                            isValid = false;
                        }
                    }
                }
                if (fields.length > 0) {
                   focusField.focus();
                   alert(fields.join('/n'));
                }
                return isValid;
            }

            function validateMaxLength(form,oMaxLength) {
                var isValid = true;
                var focusField = null;
                var i = 0;
                var fields = new Array();
//                oMaxLength = new maxlength();
                for (x in oMaxLength) {
                    var field = form[oMaxLength[x][0]];

                    if (field.type == 'text' ||
                        field.type == 'textarea') {

                        var iMax = parseInt(oMaxLength[x][2]("maxlength"));
                        if (field.value.length > iMax) {
                            if (i == 0) {
                                focusField = field;
                            }
                            fields[i++] = oMaxLength[x][1];
                            isValid = false;
                        }
                    }
                }
                if (fields.length > 0) {
                   focusField.focus();
                   alert(fields.join('/n'));
                }
                return isValid;
            }

            function validateMask(form,oMasked) {
                var isValid = true;
                var focusField = null;
                var i = 0;
                var fields = new Array();
//                oMasked = new mask();
                for (x in oMasked) {
                    var field = form[oMasked[x][0]];

                    if ((field.type == 'text' ||
                         field.type == 'textarea') &&
                         (field.value.length > 0)) {

                        if (!matchPattern(field.value, oMasked[x][2]("mask"))) {
                            if (i == 0) {
                                focusField = field;
                            }
                            fields[i++] = oMasked[x][1];
                            isValid = false;
                        }
                    }
                }

                if (fields.length > 0) {
                   focusField.focus();
                   alert(fields.join('/n'));
                }
                return isValid;
            }


            function validateByte(form,oByte) {
                var bValid = true;
                var focusField = null;
                var i = 0;
                var fields = new Array();
//                oByte = new ByteValidations();
                for (x in oByte) {
                 var field = form[oByte[x][0]];

                    if (field.type == 'text' ||
                        field.type == 'textarea' ||
                        field.type == 'select-one' ||
      field.type == 'radio') {

      var value = '';
      // get field's value
      if (field.type == "select-one") {
       var si = field.selectedIndex;
       if (si >= 0) {
        value = field.options[si].value;
       }
      } else {
       value = field.value;
      }

                        if (value.length > 0) {
                            if (!isAllDigits(value)) {
                                bValid = false;
                                if (i == 0) {
                                    focusField = field;
                                }
                                fields[i++] = oByte[x][1];

                            } else {

                             var iValue = parseInt(value);
                             if (isNaN(iValue) || !(iValue >= -128 && iValue <= 127)) {
                                 if (i == 0) {
                                     focusField = field;
                                 }
                                 fields[i++] = oByte[x][1];
                                 bValid = false;
                             }
                            }
      }

                    }
                }
                if (fields.length > 0) {
                   focusField.focus();
                   alert(fields.join('/n'));
                }
                return bValid;
            }
            function validateShort(form,ShortValidations) {
                var bValid = true;
                var focusField = null;
                var i = 0;
                var fields = new Array();
//                oShort = new ShortValidations();
                for (x in oShort) {
                 var field = form[oShort[x][0]];

                    if (field.type == 'text' ||
                        field.type == 'textarea' ||
                        field.type == 'select-one' ||
                        field.type == 'radio') {

                        var value = '';
      // get field's value
      if (field.type == "select-one") {
       var si = field.selectedIndex;
       if (si >= 0) {
        value = field.options[si].value;
       }
      } else {
       value = field.value;
      }

                        if (value.length > 0) {
                            if (!isAllDigits(value)) {
                                bValid = false;
                                if (i == 0) {
                                    focusField = field;
                                }
                                fields[i++] = oShort[x][1];

                            } else {

                             var iValue = parseInt(value);
                             if (isNaN(iValue) || !(iValue >= -32768 && iValue <= 32767)) {
                                 if (i == 0) {
                                     focusField = field;
                                 }
                                 fields[i++] = oShort[x][1];
                                 bValid = false;
                             }
                        }
                       }
                    }
                }
                if (fields.length > 0) {
                   focusField.focus();
                   alert(fields.join('/n'));
                }
                return bValid;
            }

            function validateInteger(form,oInteger) {
                var bValid = true;
                var focusField = null;
                var i = 0;
                var fields = new Array();
//                oInteger = new IntegerValidations();
                for (x in oInteger) {
                 var field = form[oInteger[x][0]];

                    if (field.type == 'text' ||
                        field.type == 'textarea' ||
                        field.type == 'select-one' ||
                        field.type == 'radio') {

                        var value = '';
      // get field's value
      if (field.type == "select-one") {
       var si = field.selectedIndex;
          if (si >= 0) {
           value = field.options[si].value;
          }
      } else {
       value = field.value;
      }

                        if (value.length > 0) {

                            if (!isAllDigits(value)) {
                                bValid = false;
                                if (i == 0) {
                                 focusField = field;
                             }
              fields[i++] = oInteger[x][1];

                            } else {
                             var iValue = parseInt(value);
                             if (isNaN(iValue) || !(iValue >= -2147483648 && iValue <= 2147483647)) {
                                 if (i == 0) {
                                     focusField = field;
                                 }
                                 fields[i++] = oInteger[x][1];
                                 bValid = false;
                            }
                           }
                       }
                    }
                }
                if (fields.length > 0) {
                   focusField.focus();
                   alert(fields.join('/n'));
                }
                return bValid;
            }

            function validateFloat(form,oFloat) {
                var bValid = true;
                var focusField = null;
                var i = 0;
                var fields = new Array();
//                oFloat = new FloatValidations();
                for (x in oFloat) {
                 var field = form[oFloat[x][0]];

                    if (field.type == 'text' ||
                        field.type == 'textarea' ||
                        field.type == 'select-one' ||
                        field.type == 'radio') {

                     var value = '';
      // get field's value
      if (field.type == "select-one") {
       var si = field.selectedIndex;
       if (si >= 0) {
           value = field.options[si].value;
       }
      } else {
       value = field.value;
      }

                        if (value.length > 0) {
                            // remove '.' before checking digits
                            var tempArray = value.split('.');
                            var joinedString= tempArray.join('');

                            if (!isAllDigits(joinedString)) {
                                bValid = false;
                                if (i == 0) {
                                    focusField = field;
                                }
                                fields[i++] = oFloat[x][1];

                            } else {
                             var iValue = parseFloat(value);
                             if (isNaN(iValue)) {
                                 if (i == 0) {
                                     focusField = field;
                                 }
                                 fields[i++] = oFloat[x][1];
                                 bValid = false;
                             }
                            }
                        }
                    }
                }
                if (fields.length > 0) {
                   focusField.focus();
                   alert(fields.join('/n'));
                }
                return bValid;
            }

            function validateDate(form,oDate) {
               var bValid = true;
               var focusField = null;
               var i = 0;
               var fields = new Array();
//               oDate = new DateValidations();
               for (x in oDate) {
                   var value = form[oDate[x][0]].value;
                   var datePattern = oDate[x][2]("datePatternStrict");
                   if ((form[oDate[x][0]].type == 'text' ||
                        form[oDate[x][0]].type == 'textarea') &&
                       (value.length > 0) &&
                       (datePattern.length > 0)) {
                     var MONTH = "MM";
                     var DAY = "dd";
                     var YEAR = "yyyy";
                     var orderMonth = datePattern.indexOf(MONTH);
                     var orderDay = datePattern.indexOf(DAY);
                     var orderYear = datePattern.indexOf(YEAR);
                     if ((orderDay < orderYear && orderDay > orderMonth)) {
                         var iDelim1 = orderMonth + MONTH.length;
                         var iDelim2 = orderDay + DAY.length;
                         var delim1 = datePattern.substring(iDelim1, iDelim1 + 1);
                         var delim2 = datePattern.substring(iDelim2, iDelim2 + 1);
                         if (iDelim1 == orderDay && iDelim2 == orderYear) {
                            dateRegexp = new RegExp("^(//d{2})(//d{2})(//d{4})$");
                         } else if (iDelim1 == orderDay) {
                            dateRegexp = new RegExp("^(//d{2})(//d{2})[" + delim2 + "](//d{4})$");
                         } else if (iDelim2 == orderYear) {
                            dateRegexp = new RegExp("^(//d{2})[" + delim1 + "](//d{2})(//d{4})$");
                         } else {
                            dateRegexp = new RegExp("^(//d{2})[" + delim1 + "](//d{2})[" + delim2 + "](//d{4})$");
                         }
                         var matched = dateRegexp.exec(value);
                         if(matched != null) {
                            if (!isValidDate(matched[2], matched[1], matched[3])) {
                               if (i == 0) {
                                   focusField = form[oDate[x][0]];
                               }
                               fields[i++] = oDate[x][1];
                               bValid =  false;
                            }
                         } else {
                            if (i == 0) {
                                focusField = form[oDate[x][0]];
                            }
                            fields[i++] = oDate[x][1];
                            bValid =  false;
                         }
                     } else if ((orderMonth < orderYear && orderMonth > orderDay)) {
                         var iDelim1 = orderDay + DAY.length;
                         var iDelim2 = orderMonth + MONTH.length;
                         var delim1 = datePattern.substring(iDelim1, iDelim1 + 1);
                         var delim2 = datePattern.substring(iDelim2, iDelim2 + 1);
                         if (iDelim1 == orderMonth && iDelim2 == orderYear) {
                             dateRegexp = new RegExp("^(//d{2})(//d{2})(//d{4})$");
                         } else if (iDelim1 == orderMonth) {
                             dateRegexp = new RegExp("^(//d{2})(//d{2})[" + delim2 + "](//d{4})$");
                         } else if (iDelim2 == orderYear) {
                             dateRegexp = new RegExp("^(//d{2})[" + delim1 + "](//d{2})(//d{4})$");
                         } else {
                             dateRegexp = new RegExp("^(//d{2})[" + delim1 + "](//d{2})[" + delim2 + "](//d{4})$");
                         }
                         var matched = dateRegexp.exec(value);
                         if(matched != null) {
                             if (!isValidDate(matched[1], matched[2], matched[3])) {
                                 if (i == 0) {
                                     focusField = form[oDate[x][0]];
                                 }
                                 fields[i++] = oDate[x][1];
                                 bValid =  false;
                              }
                         } else {
                             if (i == 0) {
                                 focusField = form[oDate[x][0]];
                             }
                             fields[i++] = oDate[x][1];
                             bValid =  false;
                         }
                     } else if ((orderMonth > orderYear && orderMonth < orderDay)) {
                         var iDelim1 = orderYear + YEAR.length;
                         var iDelim2 = orderMonth + MONTH.length;
                         var delim1 = datePattern.substring(iDelim1, iDelim1 + 1);
                         var delim2 = datePattern.substring(iDelim2, iDelim2 + 1);
                         if (iDelim1 == orderMonth && iDelim2 == orderDay) {
                             dateRegexp = new RegExp("^(//d{4})(//d{2})(//d{2})$");
                         } else if (iDelim1 == orderMonth) {
                             dateRegexp = new RegExp("^(//d{4})(//d{2})[" + delim2 + "](//d{2})$");
                         } else if (iDelim2 == orderDay) {
                             dateRegexp = new RegExp("^(//d{4})[" + delim1 + "](//d{2})(//d{2})$");
                         } else {
                             dateRegexp = new RegExp("^(//d{4})[" + delim1 + "](//d{2})[" + delim2 + "](//d{2})$");
                         }
                         var matched = dateRegexp.exec(value);
                         if(matched != null) {
                             if (!isValidDate(matched[3], matched[2], matched[1])) {
                                 if (i == 0) {
                                     focusField = form[oDate[x][0]];
                                  }
                                  fields[i++] = oDate[x][1];
                                  bValid =  false;
                              }
                          } else {
                              if (i == 0) {
                                  focusField = form[oDate[x][0]];
                              }
                              fields[i++] = oDate[x][1];
                              bValid =  false;
                          }
                     } else {
                         if (i == 0) {
                             focusField = form[oDate[x][0]];
                         }
                         fields[i++] = oDate[x][1];
                         bValid =  false;
                     }
                  }
               }
               if (fields.length > 0) {
                  focusField.focus();
                  alert(fields.join('/n'));
               }
               return bValid;
            }

            function validateRange(form,oRange) {
                return validateIntRange(form,oRange);
            }

            function validateIntRange(form,oRange) {
                var isValid = true;
                var focusField = null;
                var i = 0;
                var fields = new Array();
//                oRange = new intRange();
                for (x in oRange) {
                    var field = form[oRange[x][0]];

                    if ((field.type == 'text' ||
                         field.type == 'textarea') &&
                        (field.value.length > 0)) {

                        var iMin = parseInt(oRange[x][2]("min"));
                        var iMax = parseInt(oRange[x][2]("max"));
                        var iValue = parseInt(field.value);
                        if (!(iValue >= iMin && iValue <= iMax)) {
                            if (i == 0) {
                                focusField = field;
                            }
                            fields[i++] = oRange[x][1];
                            isValid = false;
                        }
                    }
                }
                if (fields.length > 0) {
                    focusField.focus();
                    alert(fields.join('/n'));
                }
                return isValid;
            }

            function validateFloatRange(form,oRange) {
                var isValid = true;
                var focusField = null;
                var i = 0;
                var fields = new Array();
//                oRange = new floatRange();
                for (x in oRange) {
                    var field = form[oRange[x][0]];

                    if ((field.type == 'text' ||
                         field.type == 'textarea') &&
                        (field.value.length > 0)) {

                        var fMin = parseFloat(oRange[x][2]("min"));
                        var fMax = parseFloat(oRange[x][2]("max"));
                        var fValue = parseFloat(field.value);
                        if (!(fValue >= fMin && fValue <= fMax)) {
                            if (i == 0) {
                                focusField = field;
                            }
                            fields[i++] = oRange[x][1];
                            isValid = false;
                        }
                    }
                }
                if (fields.length > 0) {
                    focusField.focus();
                    alert(fields.join('/n'));
                }
                return isValid;
            }

            function validateCreditCard(form,oCreditCard) {
                var bValid = true;
                var focusField = null;
                var i = 0;
                var fields = new Array();
//                oCreditCard = new creditCard();
                for (x in oCreditCard) {
                    if ((form[oCreditCard[x][0]].type == 'text' ||
                         form[oCreditCard[x][0]].type == 'textarea') &&
                        (form[oCreditCard[x][0]].value.length > 0)) {
                        if (!luhnCheck(form[oCreditCard[x][0]].value)) {
                            if (i == 0) {
                                focusField = form[oCreditCard[x][0]];
                            }
                            fields[i++] = oCreditCard[x][1];
                            bValid = false;
                        }
                    }
                }
                if (fields.length > 0) {
                    focusField.focus();
                    alert(fields.join('/n'));
                }
                return bValid;
            }

            function validateEmail(form,oEmail) {
                var bValid = true;
                var focusField = null;
                var i = 0;
                var fields = new Array();
//                oEmail = new email();
                for (x in oEmail) {
                    if ((form[oEmail[x][0]].type == 'text' ||
                         form[oEmail[x][0]].type == 'textarea') &&
                        (form[oEmail[x][0]].value.length > 0)) {
                        if (!checkEmail(form[oEmail[x][0]].value)) {
                            if (i == 0) {
                                focusField = form[oEmail[x][0]];
                            }
                            fields[i++] = oEmail[x][1];
                            bValid = false;
                        }
                    }
                }
                if (fields.length > 0) {
                    focusField.focus();
                    alert(fields.join('/n'));
                }
                return bValid;
            }

这样就可以实现多表单页面的验证了。

基于Springboot+Vue前后端分离的博客项目 本文介绍了一个基于SpringBoot与Vue的前后端分离个人博客系统MyBlog,涵盖文章、分类、标签、评论、友链等核心功能。项目整合了JWT鉴权、AES加密、七牛云存储、Markdown转HTML等技术,通过实战巩固了JavaWeb开发知识,提升了编码与问题解决能力。代码结构清晰,附有详细配置与部署说明,适合初学者学习参考。 阅读详情

相关推荐

海康/大华设备如何接入GB28181平台?最新2022版互联避坑指南

本文详细解析了海康/大华设备接入GB28181平台的最新2022版互联避坑指南,涵盖参数配置、实时视音频点播协议交互及典型故障排查。重点介绍了GB/T28181-2022标准下的设备编码规范、SIP服务器配置及媒体流保活机制,帮助工程团队高效解决设备离线和媒体流中断等问题。

weixin_30733003的博客 695

struts1.2中表单标签的应用---(form及text使用)源码解析

一、以text标签为例 1.配置 web.xml中 /html /WEB-INF/struts-html.tld 2.jsp中的使用 *规格说明: 3.经过struts标签处理器转换成一下内容 二、看其转换过程,源码解析 BaseFieldTag.java publ

honghailiang的专栏 1606

Pytorch版deeplabv3+环境配置训练自己的数据集

参考:https://blog.csdn.net/qq_36766560/article/details/110009622?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522161594607816780266214828%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=161594607816780266214828

Ring__Rain的博客 1万+

几个错误的解决关键

导读:   1、   org.springframework.orm.ObjectRetrievalFailureException: Object of class [com.xindeco.myregister.pojo.MyRegisterInfo] with identifier [14]: not found   MyRegisterInfo在数据库没有identifier [1

我的世界我的梦 3万+

电路中的DGND、GROUND、GROUND_REF的区别,VREF、VCC、VDD、VEE和VSS的区别?

DGND是数字地,是数字电路部分的公共基准端,用于连接数字电路的接地。

XU157303764的博客 2356

java毕设:基于springboot的服装搭配推荐系统(springboot+layui+jq+html)1011

项目描述 基于springboot的服装搭配推荐系统: 基于天气服装搭配推荐系统为用户提供未来一周的天气预报情况,并根据预报天气和用户现有的服装进行着装搭配,以及显示未来6小时精确温度数据为用户提供更精确的天气信息便于用户在出行前对自己的着装进行调整,每日用户可以根据自己当日对系统推荐的着装搭配舒适度进行反馈,系统将根据用户的反馈对用户着装的保暖系数进行相应调整,通过多次的反馈和调整形成对用户着装的个体化和精确化的推荐。 本系统可以为用户提供以下服务: 1.未来五天的天气信息显示; 2.未来六小时内天气温度

qq_2537071370的博客 3648

struts-html标签库

base org.apache.struts.taglib.html.BaseTag button org.apache.struts.taglib.html.ButtonTag cancel org.apache.struts.taglib.html.CancelTag checkbox org.apache.struts.taglib.html.CheckboxTag errors org.a

Free 2262

Opus Clip AI技术浅析(一)

Opus Clip AI 是一款由Opus公司推出的AI视频剪辑工具,旨在通过人工智能技术简化视频编辑过程,帮助用户快速从长视频中提取精彩片段,并生成适合社交媒体分享的短视频。

m0_75253143的博客 2156

基于Springboot3 + Vue3 +Agent+RAG+Function Calling+MySQL的智慧墓园管理系统

本文介绍基于SpringBoot3+Vue3+AIAgent打造的智慧墓园管理系统,融合RAG、FunctionCalling与多轮对话,实现家属建档、预约审核、AI助手答疑等全流程闭环。项目具备真实业务场景、完整权限体系与企业级架构设计,是学习AI Agent开发、全栈实战与作品集构建的理想案例。建议按“跑通→读业务→攻AI”三步学习,快速掌握大模型落地核心能力。

深耕开发,专注编程实战。分享源码解析、项目搭建、问题排查笔记,沉淀技术,持续更新。 162

FC7300 SPI MCAL配置引导

Example - QMI8A01z外设:Example - QMI8A01z外设:

舊梦的博客 263

YOLO11涨点优化:训练技巧 | 使用标签平滑(Label Smoothing)配合余弦退火学习率,防止过拟合,稳步提点

摘要: YOLO11凭借动态卷积核调度、自适应特征融合等创新成为2026年目标检测主流,但面临训练集过拟合问题。文章聚焦两种零推理开销的正则化技巧:标签平滑(Label Smoothing)和余弦退火学习率(Cosine Annealing LR)。标签平滑通过软化硬标签(如将[1,0]改为[0.9,0.1])防止模型过度自信,代码中通过label_smoothing=0.1一键启用;余弦退火则以平滑的余弦曲线调整学习率(cos_lr=True),避免阶梯衰减的震荡。两者组合可显著缩小YOLO11训练与验证

2601_95807009的博客 47

基于Spring Boot和Vue的法律咨询案件进度与文书管理系统设计与实现

按实际代码介绍客户、律师、助理和管理员的页面分工,以及案件节点、预约确认、文书正文和版本记录管理。说明文书生成按钮的示例实现,并给出 Spring Boot、Vue 与 H2 环境的本地启动方法。

weixin_63587281的博客 213

AHB—SRAMC项目(结构图,核心代码、Testbench架构)

文章目录一、AHB_SRAMC项目介绍1.1.AHB总线控制单元(ahb_slv_if.v)1.2.SRAM控制单元(sramc_top.v)1.3.主要的传输路径二、结构框图2.1.AHB_SRAMC结构图(重点)2.2.总线控制单元与SRAM控制单元结构图三、部分核心代码(重点理解)四、SystemVerilog Testbench架构(重点)五、目录结构 一、AHB_SRAMC项目介绍 本项...

Mr.翟的博客 3万+

JavaScript编程篇之浏览器存储与调试:刷新后,筛选词从哪里回来

用一个筛选框验证localStorage如何保存偏好、恢复输入,以及如何用断点定位损坏的记录。

code2cat的博客 499

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

读者社区图书借阅系统

一个基于现代化技术栈构建的综合性图书馆管理系统,集成了图书借阅、座位预约、活动管理、在线咨询及完善的会员与财务管理功能。系统采用前后端分离架构,提供极致的用户体验和强大的后台管理能力。欢迎提交 Issue 或 Pull Request 来改进本项目。本项目仅供学习与交流使用。

aiyuanma_vip的博客 291

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

JavaScript|第36章:实时通信

本章系统讲解实时通信技术,对比传统HTTP请求的局限性,介绍短轮询、长轮询、Server-Sent Events(SSE)与WebSocket四种方案。重点掌握WebSocket双向通信机制,包括握手、心跳、断线重连及协议封装,并通过实战实现支持重连的实时聊天室,结合场景完成技术选型与降级策略设计。

xhmico的博客 239

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

JavaScript简单数据类型和复杂数据类型

简单数据类型:按值存储在栈内存中,包括 Number、String、Boolean、undefined、null、Symbol、BigInt。复杂数据类型:引用存储在栈中、实际数据存储在堆中,包括 Object、Array、Function、Date、RegExp、Map、Set、WeakMap、WeakSet、Promise、Proxy 等。掌握 JavaScript 数据类型与栈堆内存的区别,能帮助你写出更高效、更少内存泄漏的代码。

大今野 166

鸿蒙 PC 上的 React Native 备件台账,筛掉一半记录后怎样回到原来的物料

一张备件台账可能有几十行。用户进详情复核后,返回列表是为了接着看旁边的记录;在此期间若筛选条件变化,用旧的滚动偏移就未必回到原物料附近。这里给每条物料一个可核对的编号,用邻近行证明 React Native 页面恢复的是谁。从维修仓接到的任务是找 SP-040,打开详情核对一次,再返回到它附近。我把它做成鸿蒙 PC 上的一次 React Native 台账巡检,给每一步都留了一个邻居。全表里 SP-040 下面是 SP-041,筛掉待入库项以后,下面换成 SP-042。

程序猿追的博客 76

LangGraph 快速入门:从 StateGraph 到 ReAct Agent

本文介绍了Python中TypedDict的用途及其在类型检查中的作用,强调其作为字典结构说明书的功能。随后结合图论中的有向图概念,讲解了LangGraph如何利用有向图实现Agent流程编排,并通过ReAct Agent实例展示了状态定义、节点构建与条件边控制的完整流程,最终实现基于LLM与工具调用的智能交互系统。

2301_80002260的博客 170

临时电脑没装办公软件?我用 Godot 导出 Web 页面,在浏览器里拼出一套轻量办公桌面

针对临时设备缺乏办公环境的痛点,本文记录使用 Godot 4.2 导出 Web 版本,从零搭建一套运行在浏览器内的“办公桌面”原型。内容涵盖方案选型对比、窗口管理器架构设计、核心交互代码实现、WASM 包体与内存优化策略,以及实际跑通后的能力边界。文章聚焦工程落地中的结构取舍、性能瓶颈和前后端协同路径,不包含泛泛概念,只输出可复用的实现思路与验证过的结论。

2402_83344867的博客 537

英语教学管理平台纯码实战开发 03:搭建管理后台基础布局,实现左右分栏

左侧菜单

低代码布道师的博客 308

JS - 设计模式基础

本文系统阐述设计模式的基础概念与核心原则,强调其在提升代码质量、可维护性与可扩展性中的关键作用。聚焦SOLID原则,以单一职责(SRP)和开闭原则(OCP)为例,结合JS/TS及React开发实践,展示如何通过函数拆分、组件组合、Hook封装等手段实现逻辑解耦。总结指出,设计模式是面向对象思想的具象化落地,尤其在前端领域支撑组件化、状态管理与工程降本,助力团队高效协作与系统演进。

D_xw_的博客 154

浏览器端 Whisper 语音识别完整实践:ffmpeg.wasm + transformers.js 架构、踩坑与性能实测

本文实现浏览器端零服务端语音识别,基于ffmpeg.wasm抽音轨、@xenova/transformers加载Whisper ONNX模型,全程前端完成转写与导出。重点剖析三大工程坑:Blob Worker模块路径解析错误(需用location.origin拼绝对路径)、@ffmpeg/core-st包名错误(应为@ffmpeg/core)、WASM单线程性能瓶颈。实测表明,10分钟音频耗时约25分钟,适合隐私敏感、低频使用场景。建议选用小模型(如tiny)平衡速度与准确率,明确能力边界,避免不切实际的性

ai-codex-python博客 251

Github Pages deploy action - deploy Node.js 20 is deprecated error&warning

GitHub Actions 已弃用 Node.js 20,相关 Action(如 configure-pages@v5、upload-artifact@v4)被强制运行在 Node.js 24,引发警告。为消除警告,需升级至原生支持 Node 24 的版本:configure-pages@v6、upload-pages-artifact@v5、deploy-pages@v5 及 upload-artifact@v6。建议同步移除 FORCE_JAVASCRIPT_ACTIONS_TO_NODE24 等临时

★【World Of Moshow 郑锴】★ 304

DeepSeek Harness 解读 1· 拆解一个 TypeScript CLI:从参数解析到类型安全的命令分发

本文拆解了一个TypeScript CLI的入口设计,展示如何通过runCli函数实现参数解析、类型安全分发与动态加载。核心思想包括:使用parseDshArgs解析命令行,switch按模式分发任务,动态导入模块降低启动开销,仅捕获预期错误并返回合理退出码,利用never确保分支完整性,并支持直接执行与模块导入。该设计职责清晰、可扩展性强,是构建健壮CLI的理想范式。

Joey 的工作空间~ 424
上一篇: 主关键字建立分析
下一篇: 如何实现对页面select进行强制赋值
hellenlong
博客等级 码龄25年 2粉丝 9原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值