zoukankan      html  css  js  c++  java
  • Ajax 与 Struts 1

    Xml配置

    <action path="/product/product/validateCurrencyDecimalSupport"
    type="com.neulion.iptv.ui.struts.AdvancedAction"
    parameter="validateCurrencyDecimalSupport" name="AdvancedPriceForm" validate="false" scope="request">
    <forward name="success" path=".result"></forward>
    </action>

    tiles

    <definition name=".result" path="/WEB-INF/jsp/result.jsp"/>

    result.jsp

    <%@page contentType="text/html;charset=utf-8"%>${result}

    ajax:

    function validateCurrencyDecimalSupport(amountType, amountPrice)

    {
    var retval = "supported";
    $.ajax({
    type: "POST",
    url: "validateCurrencyDecimalSupport.do",
    timeout: 2000,
    async: false,
    data: { amountType: amountType, amountPrice: amountPrice },
    success: function(data) {
    //show content
    retval = data;
    },
    error: function(jqXHR, textStatus, err) {
    //show error message
    alert('text status '+textStatus+', err '+err)
    }
    });
    return retval;
    }

    AdvancedAction Action:

    public ActionForward execute(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response)
    throws Exception
    {
    String result = SUCCESS;
    String param = mapping.getParameter();
    Map args = new HashMap();
    DynaActionForm dyForm = (DynaActionForm) form;

    if ("validateCurrencyDecimalSupport".equalsIgnoreCase(param))
    {
    validateCurrencyDecimalSupport(request);
    }

      return redirect(mapping, result, args);

    }

    private void validateCurrencyDecimalSupport(HttpServletRequest request)
    {
    String amount = new BigDecimal(request.getParameter("amountPrice")).stripTrailingZeros().toString();
    Integer decimalSupport = BaseServiceFactory.getCurrencyService().getCurrencyType(request.getParameter("amountType").trim()).getDecimalSupport();
    if (amount.indexOf(".") > 0 && (amount.split("\.")[1].length() > decimalSupport.intValue()))
    request.setAttribute("result", "The decimal support of currency is : " + decimalSupport.intValue() + ", please input a valid number");
    else
    request.setAttribute("result", "supported");
    }

     

  • 相关阅读:
    python3.x学习笔记2018-02-05更新
    网络安全学习资源整理2018-02-02更新
    隔行变色效果
    自制滚动条
    关于ico图标
    CSS实现标题/段落省略效果的三剑客
    第三章(循环) 编程题 2
    第三章(循环) 编程题
    python基础03--基本数据类型(字符串)
    python基础02--运算符与基本数据类型(数字)
  • 原文地址:https://www.cnblogs.com/daxiong225/p/8277239.html
Copyright © 2011-2022 走看看