欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
開(kāi)發(fā)Spring MVC應用程序(3-2)

22)增加表單

l         下面增加一個(gè)允許用戶(hù)輸入百分值的表單。由于表單中使用了Spring的標記,所以將dist/spring.tld導入到springapp/WEB-INF目錄下,并在web.xml中增加<taglib>條目

  <taglib>
    <taglib-uri>/spring</taglib-uri>
    <taglib-location>/WEB-INF/spring.tld</taglib-location>
  </taglib>

l         在表單頁(yè)面priceincrease.jsp中,定義了包含一個(gè)輸入增加百分比的文本域和提交按鈕的表單

<%@ include file="/WEB-INF/jsp/include.jsp" %>
<%@ taglib prefix="spring" uri="/spring" %>
 
<html>
<head><title><fmt:message key="title"/></title></head>
<body>
<h1><fmt:message key="priceincrease.heading"/></h1>
<form method="post">
  <table width="95%" bgcolor="f8f8ff" border="0" cellspacing="0" cellpadding="5">
    <tr>
      <td alignment="right" width="20%">Increase (%):</td>
      <spring:bind path="priceIncrease.percentage">
        <td width="20%">
          <input type="text" name="percentage" value="<c:out value="${status.value}"/>">
        </td>
        <td width="60%">
          <font color="red"><c:out value="${status.errorMessage}"/></font>
        </td>
      </spring:bind>
    </tr>
  </table>
  <br>
  <spring:hasBindErrors name="priceIncrease">
    <b>Please fix all errors!</b>
  </spring:hasBindErrors>
  <br><br>
  <input type="submit" alignment="center" value="Execute">
</form>
<a href="<c:url value="hello.htm"/>">Home</a>
</body>
</html>

l         <spring:bind>綁定文本域到Command對象(后面介紹)的屬性(由path屬性指定),status.value變量表示綁定屬性的值,status.errorMessage變量表示驗證錯誤時(shí)返回的錯誤信息

l         <spring:hasBindErrors>綁定錯誤到指定對象(由name屬性指定)

l         Command對象是個(gè)簡(jiǎn)單的JavaBean,傳遞給驗證器,如果驗證通過(guò),再傳遞給控制器

package bus;
 
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
 
public class PriceIncrease {
 
    /** Logger for this class and subclasses */
    protected final Log logger = LogFactory.getLog(getClass());
 
    private int percentage;
 
    public void setPercentage(int I) {
        percentage = I;
        logger.info(“Percentage set to “ + I);
    }
 
    public int getPercentage() {
        return percentage;
    }
 
}

l         用戶(hù)提交表單時(shí),表單的數據由Spring設置到Command對象中,并調用驗證器進(jìn)行數據有效性驗證

package bus;
 
import org.springframework.validation.Validator;
import org.springframework.validation.Errors;
 
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
 
public class PriceIncreaseValidator implements Validator {
    private int DEFAULT_MIN_PERCENTAGE = 0;
    private int DEFAULT_MAX_PERCENTAGE = 50;
    private int minPercentage = DEFAULT_MIN_PERCENTAGE;
    private int maxPercentage = DEFAULT_MAX_PERCENTAGE;
 
    /** Logger for this class and subclasses */
    protected final Log logger = LogFactory.getLog(getClass());
 
    public boolean supports(Class clazz) {
        return clazz.equals(PriceIncrease.class);
    }
 
    public void validate(Object obj, Errors errors) {
        PriceIncrease pi = (PriceIncrease) obj;
        if (pi == null) {
            errors.rejectValue("percentage", "error.not-specified", null, "Value required.");
        }
        else {
            logger.info("Validating with " + pi + ": " + pi.getPercentage());
            if (pi.getPercentage() > maxPercentage) {
                errors.rejectValue("percentage", "error.too-high",
                    new Object[] {new Integer(maxPercentage)}, "Value too high.");
            }
            if (pi.getPercentage() <= minPercentage) {
                errors.rejectValue("percentage", "error.too-low",
                    new Object[] {new Integer(minPercentage)}, "Value too low.");
            }
        }
    }
 
    public void setMinPercentage(int i) {
        minPercentage = i;
    }
 
    public int getMinPercentage() {
        return minPercentage;
    }
 
    public void setMaxPercentage(int i) {
        maxPercentage = i;
    }
 
    public int getMaxPercentage() {
        return maxPercentage;
    }
 
}

l         驗證器實(shí)現Validator接口,該接口有兩個(gè)方法:

Ø         supports():決定指定類(lèi)的對象是否能夠驗證

Ø         validate():實(shí)現驗證對象,提供兩個(gè)參數,一個(gè)是驗證對象,一個(gè)是我們構建的包含與域屬性相關(guān)的錯誤消息的Errors;錯誤消息可以使用前面介紹的status.errorMessage變量獲取

l         Errors對象的rejectValue()方法用來(lái)彈出驗證對象指定域屬性的指定錯誤描述,它包含四個(gè)參數:屬性名,消息key值(消息在屬性文件中定義),消息參數(提供動(dòng)態(tài)消息)和缺省消息

本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
Spring Framework標記庫初學(xué)者指南
Consumption helps to stabilize economy
spring mvc 傳統表單提交亂碼問(wèn)題
spring security 3 中使用自定義數據庫來(lái)設置權限
Spring Boot實(shí)戰之配置使用Sentry上報錯誤日志(二)
springmvc中自己實(shí)現的token防表單重復提交,防止二次提交
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久