从jsp发送参数到struts2动作类的方法 [英] send argument from jsp to struts2 action class's method
问题描述
这是以下 2 个链接的延续......由于我无法对这些链接发表任何评论......
<块引用>1.根据从 struts2 应用程序中的下拉列表中选择的值填充表
和
<块引用>我也有同样的情况,我需要根据下拉列表中的选定值打印表格,在我的谷歌搜索中,我得到了这个页面,我在这里使用了建议.但是,当我在下拉列表中选择一个值时,我会打印表格,并且页面仍然停留在同一页面上而没有任何更新,下面是我的代码...帮我解决这个问题...
javascript
在jsp体内
<s:select label="Select Batch" headerKey="-1" headerValue="选择一个批次..."list="%{#session.Batchs}" Value="batch" name="batch" onchange="showAllocationStatusJavaScript()" id="batch"/>
网址标签
<s:url action="doShowAllocationStatus" var="batchURL"><param value="%{batch}"/></s:url>
这是打印我的列表的表格
<table align="center" border="2"><tr><th>TAN</th><th>策展人</th><th>策展人状态</th><th>QC</th><th>QC状态</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:迭代器>
struts.xml
AllocateTAN 操作类
//保存数据的字段...私人列表allocationList = new ArrayList();私有字符串批处理;私人列表<字符串>批次 = 新的 ArrayList();私人字符串 TAN;私人列表<字符串>Tans = new ArrayList();私人字符串用户;私人列表<字符串>users = new ArrayList();//以及所有的 getter 和 setter.........//用于访问数据库的变量...CationDAO dao1 = new CationDAO() ;//流程 1:使所有详细信息可用于分配的 TAN 页面...当页面页面第一次加载时public String AllocatingTANpageDetails() 抛出 SQLException{Mapsession=ActionContext.getContext().getSession();this.batchs=dao1.Batch_List();session.put("批次", 批次);//Tans=dao1.Tan_list(getBatch());this.users=dao1.Users_List();session.put("用户", 用户);返回成功;}private void showTANlist(String Batch1) 抛出 SQLException{Mapsession=ActionContext.getContext().getSession();Tans=dao1.Tan_list(Batch1);session.put("Tans", Tans);}//流程 2.:在同一页面中以表格形式显示分配状态...公共字符串 showAllocationStatus() 抛出 SQLException {Mapsession=ActionContext.getContext().getSession();//setBatch(batch_value);session.put("批次",批次);showTANlist(batch);System.out.println("正在处理分配列表...");this.allocationList=(List)dao1.status(batch);System.out.println("完成...");返回成功;}//执行为用户分配TAN的方法...公共字符串执行(){返回成功;}
您的 jQuery 选择器不正确:
$('myTableWrapper').html(result);
DOM 元素 ID 由前导 #
字符指定;这应该是:
$('#myTableWrapper').html(result);
您的 $.ajax
参数中还有一个多余的尾随逗号,它会在某些浏览器上中断,应始终消除.
function showAllocationStatusJavaScript() {$.ajax({url: "<s:property value='#batchURL'/>",类型:'获取',发送前:函数(){$("#loading").show();},成功:功能(结果){如果(结果!= ''){$('#myTableWrapper').html(result);}$("#loading").hide();}});}
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
and
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>
inside the jsp body
<s:select label="Select Batch" headerKey="-1" headerValue="Select a Batch..."list="%{#session.Batchs}" Value="batch" name="batch" onchange="showAllocationStatusJavaScript()" id="batch"/>
URL Tag
<s:url action="doShowAllocationStatus" var="batchURL"><param value="%{batch}"/></s:url>
this the table to print my list
<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 action class
//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;
}
Your jQuery selector is incorrect:
$('myTableWrapper').html(result);
DOM element IDs are specified by a leading #
character; this should be:
$('#myTableWrapper').html(result);
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屋!