내 JSP에서는 하나의 Table1에서 일부 값을 선택하고 Add 단추를 사용하여 다른 Table2 Table2에 추가하려고합니다. 여기struts 2의 액션에서 jsp로 생성 된 테이블의 값을 얻는 방법은 무엇입니까?
<%@page contentType="text/html;charset=UTF-8" language="java"
pageEncoding="UTF-8"%>
<%@taglib prefix="s"uri="/struts-tags"%>
<!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Insert title here</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" />
<script type="text/javascript">
$(document).ready(function(){
$('#add').on("click", function(){
$('#one tbody input:checked').parent().parent()
.appendTo("#two tbody");
return false;
});
$('#remove').on("click", function(){
$('#two tbody input:checked').parent().parent()
.appendTo("#one tbody");
return false;
});
});
function GetCellValues() {
var oTable = document.getElementById('two');
var mycars = new Array();
var mycars1 = new Array();
var mycars2 = new Array();
//gets table
var rowLength = oTable.rows.length;
//gets rows of table
for (i = 0; i < rowLength; i++){
//loops through rows
var oCells = oTable.rows.item(i).cells;
//gets cells of current row
var cellLength = oCells.length;
for(var j = 0; j < cellLength; j++){
//loops through each cell in current row
//get your cell info here
var cellVal = oCells.item(j).innerHTML;
alert(cellVal);
if(j==3){
mycars[i] = cellVal;
}
if(j==1){
mycars1[i] = cellVal;
}
if(j==2){
mycars2[i] = cellVal;
}
}
}
window.location ="DynamicTable?mytable="+mycars;
}
</script>
</head>
<body>
<button onclick="GetCellValues()">Submit</button>
<table id="one" style="border:1px solid red;">
<caption>Table 1</caption>
<thead>
<tr>
<th ></th>
<th> Id</th>
<th>Name</th>
<th>Status</th>
<th>Type</th>
<th>RollUp Type</th>
<th>System</th>
</tr>
</thead>
<tbody>
<s:iterator value="formList1">
<tr>
<td><s:checkbox theme="simple" ></s:checkbox>
</td>
<td><s:property value="id"/></td>
<td><s:property value="named"/></td>
<td><s:property value="status"/></td>
<td><s:property value="type"/></td>
<td><s:property value="rollup"/></td>
<td><s:property value="unit"/></td>
</tr>
</s:iterator>
</tbody>
</table>
<table id="two" style="border:1px solid green;">
<caption>Table 2</caption>
<thead>
<tr>
<th ></th>
<th> Id</th>
<th>Name</th>
<th>Status</th>
<th>Type</th>
<th>RollUp Type</th>
<th>System</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<br><hr><br>
<button id="add">Add</button>
<button id="remove">Remove</button>
</body>
</html>
어떻게 내가 Struts2에서 전송 버튼을 클릭하면 내 행동에 표 2에 추가 된 값을 검색 할이 내 JSP입니까?
이것은 내가 시도한 것으로, Submit 버튼을 클릭하면 javacript GetCellValues ()가 호출되어 mycars, mycars1 배열의 각 열을 설정합니다.
내 액션 클래스에는 getters와 setters가 있습니다. 그러나 제 행동에서 나는이 값들을 검색 할 수 없습니다.
조치에서 JSP로 생성 된 테이블의 값을 얻는 방법은 무엇입니까?
UPDATE : 난 그냥 지금은 쉼표로 구분 된 문자열로 액션의 값을 받고 있어요 라인 window.location ="DynamicTable?mytable="+mycars;
수정. 내가 사용했던 것보다 다른 방법이 있는지 알고 싶습니다.
웹 서버에서 지원하는 표준 방법을 사용하십시오. –
나는 그것을 사용했지만 걱정하지 않는다. – user2077648
아니, 그렇지 않았다! 네가 그렇게했다면 나는 그것을 보았다. –