⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 htmlerrorform.java

📁 一个使用htmltaglib的代码,在网上或书籍上一般都看不到
💻 JAVA
字号:
package htmltaglibs.forms;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;


public class HtmlErrorForm extends ActionForm {

  // Default bean constructor
  public HtmlErrorForm() { }

  private boolean checkbox1;
  public boolean getCheckbox1() { return this.checkbox1; }
  public void setCheckbox1(boolean checkbox1) { this.checkbox1 = checkbox1; }

  // --------------------------------------------------------- Public Methods

    /**
     * Reset all properties to their default values.
     *
     * @param mapping The mapping used to select this instance
     * @param request The servlet request we are processing
     */
     public void reset(ActionMapping mapping, HttpServletRequest request) {
         this.setCheckbox1(false);
     }

     /**
      * Validate the properties posted in this request. If validation errors are
      * found, return an <code>ActionErrors</code> object containing the errors.
      * If no validation errors occur, return <code>null</code> or an empty
      * <code>ActionErrors</code> object.
      *
      * @param mapping The current mapping (from struts-config.xml)
      * @param request The servlet request object
      * @return ActionErrors The ActionErrors object containing the errors.
      */
     public ActionErrors validate(ActionMapping mapping,
                                  HttpServletRequest request) {

         ActionErrors errors = new ActionErrors();

         /*
          * If the checkbox is checked, display error messages
          */
         if ( this.getCheckbox1() ) {

             // First, a GLOBAL_ERROR message for the entire page.
             errors.add(ActionMessages.GLOBAL_MESSAGE,
                     new ActionMessage("error.global.fromform") );
             // Also, display a specific error for this parameter
             errors.add("checkbox1", new ActionMessage("error.checkbox"));
         }

         return errors;
     }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -