【问题标题】:How to call Java Action using ajax如何使用 ajax 调用 Java Action
【发布时间】:2013-03-19 12:32:30
【问题描述】:

我是 AJAX 新手。我在 JSP 中有两个下拉列表,基于从第一个下拉列表中选择一个值,我需要从后端填充第二个下拉列表中的值。 我尝试在 struct1.2 中通过 AJAX 执行上述功能。

我在 onChangePrdGrp[JavaScript Function] 中使用了以下代码:

var prdGrp = document.getElementById('strProductGroup').value;
if("" != prdGrp){
    var xmlhttp;

    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    document.getElementById('prdPitch').style.display = "block";
    document.forms[0].module.value= "getProductPicthed";
    xmlhttp.open("POST","/lmsGetPrdPitched.do?prdGrp="+prdGrp,true);
    xmlhttp.send();
}else{
    document.getElementById('prdPitch').style.display = "none";
    document.getElementById('strProductPitched').value = "";
    document.getElementById('strProduct').value = "";
}

DropDown1:

<tr>
<td style="text-align: left" width="20%">Product Group</td>
<td style="text-align: left" width="20%"><html:select
property="strProductGroup" style="width:180px;"
onchange="onChangePrdGrp()">
<html:option value="">select</html:option>
<html:optionsCollection name="ProdGrpList" />
</html:select></td>
</tr>

DropDown 2:[需要在此 DropDown 中填充值]

<tr id="prdPitch">
     <td style="text-align: left" width="20%">Product Pitched</td>
     <td style="text-align: left" width="20%"><html:select
      property="strProductPitched" style="width:180px;">
      <html:option value="">select</html:option>
      <%if(null != ProductPitchList) { %>
      <html:optionsCollection name="ProductPitchList" />
      <%} %>
      </html:select></td>
</tr>

请就此向我提出建议。

【问题讨论】:

  • JQuery 肯定会让你的生活更轻松。
  • 我也不知道 JQuery。请给我建议。

标签: java ajax jsp struct


【解决方案1】:

如果你使用jQuery就很简单

see here for example

这里他们给出了很好的例子。记得插入jQuery相关的js文件

包括以下文件

<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>

【讨论】:

  • @Raghu King 你看到我的回答了吗
  • 是的,我正在调查。
  • 如何调用特定方法
  • 我必须使用哪一个?请给我建议。
  • @Raghu King 对不起,我不知道 struts1 调用方法的确切信息。我正在研究 struts2。
猜你喜欢
  • 2011-01-18
  • 2015-07-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-23
  • 1970-01-01
  • 2011-05-24
相关资源
最近更新 更多