如题 本人玩了2小时硬是没玩出个所以然来 还求大神解释
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<!-- 引入jQuery -->
<script src="jslib/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
function submit(id,url){
document.getElementById(id).action = url;
document.getElementById(id).submit() ;
} </script>
<center>
<tbody>
<c:forEach items="${list}" var="one">
<form id="${one.sid }" method="post">
<tr>
<td>
<input type="checkbox" />
<input name="sid" type="hidden" value="${one.sid }" />
</td>
<td>
${one.sname }
<input name="sname" type="hidden" value="${one.sname }" />
</td>
<td>
${one.sex }
<input name="sex" type="hidden" value="${one.sex }" />
</td>
<td>
${one.age }
<input name="age" type="hidden" value="${one.age }" />
</td>
<td>
<input type="button" value="修改"
onclick="javascript:submit(${one.sid },updstudent.action);" />
</td>
<td>
<input type="button" value="删除"
onclick="javascript:submit(${one.sid },delstudent.action);" />
</td>
</tr>
</form>
</c:forEach>
</tbody>
</table>
</center>
buttonstrutsjs页面跳转
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<!-- 引入jQuery -->
<script src="jslib/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
function submit(id,url){
document.getElementById(id).action = url;
document.getElementById(id).submit() ;
} </script>
<center>
<tbody>
<c:forEach items="${list}" var="one">
<form id="${one.sid }" method="post">
<tr>
<td>
<input type="checkbox" />
<input name="sid" type="hidden" value="${one.sid }" />
</td>
<td>
${one.sname }
<input name="sname" type="hidden" value="${one.sname }" />
</td>
<td>
${one.sex }
<input name="sex" type="hidden" value="${one.sex }" />
</td>
<td>
${one.age }
<input name="age" type="hidden" value="${one.age }" />
</td>
<td>
<input type="button" value="修改"
onclick="javascript:submit(${one.sid },updstudent.action);" />
</td>
<td>
<input type="button" value="删除"
onclick="javascript:submit(${one.sid },delstudent.action);" />
</td>
</tr>
</form>
</c:forEach>
</tbody>
</table>
</center>
buttonstrutsjs页面跳转
你想传sid过去在js代码中这样写你引入jQuery后
function submit() {
var formObj = document.form1;
formObj.action = "delstudent.action"+${message.sid};
formObj.submit();
}
需要注意的是这是才有form表单方式
就是在你表格外上下加form
在上面的form表单中 name="form1" method="post"
action中例 :private Message message;
我目前使用struts2 jsp页面传数据都是这样操作的
每个学生都是单独的form
我要修改哪个学生就提交哪个表单
所以表单名不可能直接命名啊
而且我不想在delstudent.action后面加参数
直接提交表单就能获得参数