将参数从jsp发送到struts2动作类的方法 [英] send argument from jsp to struts2 action class's method
问题描述
这是以下2个链接的延续....由于我无法对此发表任何评论...
this is the continuation of the following 2 links .... due to I was unable to post any comments for these...
1. Populating a table based on values chosen from a drop down in struts2 application
和
2. Struts2 parameter to javascript
我也有相同的情况,我需要基于从下拉列表中选择的值打印表格,在我的Google搜索中,我得到了此页面,并在这里使用了建议.但是,当我在下拉列表中选择一个值时,我得到打印的表格,并且页面仍停留在同一页面上而没有任何更新,下面是我的代码...在此帮助我...
I too have the same scenario where i need to print a table based on the selected value from the drop down list, in my google search I got this page and I used suggestions here. But when I select a value in my drop down list I get on table printed and the page still staying in the same page without any updation and below is my code ...help me out in this...
javascript
<script type="text/javascript">
function showAllocationStatusJavaScript(){
var batchURL1="<s:property value="#batchURL"/>";
$.ajax({
url:batchURL1,
type: 'get',
beforeSend: function(){
$("#loading").show();
alert("parsed");
},
success: function(result){
if(result!=''){
$('myTableWrapper').html(result);
} else {
alert(result);
}
},
});
}
</script>
在jsp主体内部
<s:select label="Select Batch" headerKey="-1" headerValue="Select a Batch..."list="%{#session.Batchs}" Value="batch" name="batch" onchange="showAllocationStatusJavaScript()" id="batch"/>
URL标记
<s:url action="doShowAllocationStatus" var="batchURL"><param value="%{batch}"/></s:url>
此表以打印我的列表
<div id="myTableWrapper">
<table align="center" border="2">
<tr>
<th>TAN</th>
<th>Curator</th>
<th>Curator Status</th>
<th>QC</th>
<th>QC Status</th>
</tr>
<s:iterator value="allocationList" >
<tr>
<td><s:property value="tan"/></td>
<td><s:property value="curator"/></td>
<td><s:property value="curator_status"/></td>
<td><s:property value="qc"/></td>
<td><s:property value="qc_status"/></td>
</tr>
</s:iterator>
</table>
</div>
struts.xml
<action name="doShowAllocationStatus" class="controller.AllocateTAN" method="showAllocationStatus" >
<result name="success" type="dispatcher" >Allocation.jsp</result>
AllocateTAN操作类
//Fields that hold data...
private List<BatchInfo> allocationList =new ArrayList<BatchInfo>();
private String batch;
private List<String> batchs = new ArrayList<String>();
private String TAN;
private List<String> Tans = new ArrayList<String>();
private String user;
private List<String> users = new ArrayList<String>();
//and all getters and setters....
.....
//variable used to access DataBase...
CationDAO dao1 = new CationDAO() ;
//flow 1.: making all details available for the allocate TAN page...when page page is loaded 1st time
public String AllocatingTANpageDetails() throws SQLException{
Map<String, Object>session=ActionContext.getContext().getSession();
this.batchs=dao1.Batch_List();
session.put("Batchs", batchs);
//Tans=dao1.Tan_list(getBatch());
this.users=dao1.Users_List();
session.put("users", users);
return SUCCESS;
}
private void showTANlist(String Batch1) throws SQLException{
Map<String, Object>session=ActionContext.getContext().getSession();
Tans=dao1.Tan_list(Batch1);
session.put("Tans", Tans);
}
//flow 2.: showing Allocation Status in Table form...in same page
public String showAllocationStatus() throws SQLException {
Map<String, Object>session=ActionContext.getContext().getSession();
//setBatch(batch_value);
session.put("Batch",batch);
showTANlist(batch);
System.out.println("Processing Allocation List... ");
this.allocationList=(List<BatchInfo>)dao1.status(batch);
System.out.println("Finished...");
return SUCCESS;
}
//execute method form allocating a TAN for a user...
public String execute(){
return SUCCESS;
}
推荐答案
您的jQuery选择器不正确:
Your jQuery selector is incorrect:
$('myTableWrapper').html(result);
DOM元素ID由前导#
字符指定;应该是:
DOM element IDs are specified by a leading #
character; this should be:
$('#myTableWrapper').html(result);
您在$.ajax
参数中也有一个多余的尾部逗号,该逗号在某些浏览器中会中断,应始终删除.
You also have an extraneous trailing comma in your $.ajax
arguments, which will break on some browsers and should always be eliminated.
function showAllocationStatusJavaScript() {
$.ajax({
url: "<s:property value='#batchURL'/>",
type: 'get',
beforeSend: function() {
$("#loading").show();
},
success: function(result) {
if (result != '') {
$('#myTableWrapper').html(result);
}
$("#loading").hide();
}
});
}
这篇关于将参数从jsp发送到struts2动作类的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!