JSP: 页面:
<%@ page language="java" pageEncoding="GBK"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%
request.setAttribute("path",request.getContextPath());
%>
<html>
<body>
<center>
<s:form action="borrowBook.action">
<table>
<tr>
<th>序号</th>
<th>书号</th>
<th>书名</th>
<th>用户</th>
</tr>
<s:iterator value="abook" status="st" >
<!-- 隐藏域 得到 用户的id -->
<input type="hidden" name="bookId" value="<s:property value="id"/>" >
<!-- 此处 写一个隐藏域,name为bookId 要想将该值(在提交表单时)传给 对应的action 应该在目标action中 定义一个属性 为 bookId 也就是hidden 中 name 的值! (private Long bookId;)并且也提供get/set方法-->
<tr>
<td><s:property value="#st.count"/></td>
<td><s:property value="book.bno"/></td>
<td><s:property value="bname"/></td>
<td>
<s:select name="userId"
list="userNames"
listKey="id"
listValue="uname"
id="selectid"
emptyOption="-1"
headerValue="选择用户"
></s:select>
</td>
</tr>
</s:iterator>
</table>
<s:submit value="提交"></s:submit>
</s:form>
<input type="button" value="submit" onclick="get()"/>
</center>
</body>
</html>
action:类:
public class BookAction{
private Long bookId;
/**
此处的bookId必须和jsp页面的要传向Action的 值的name 值相同
*/
public Long getBookId() {
return bookId;
}
public void setBookId(Long bookId) {
this.bookId = bookId;
}
public String borrowBook(){
System.out.println("JSP bookId: "+bookId);
}
}
<%@ page language="java" pageEncoding="GBK"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<%
request.setAttribute("path",request.getContextPath());
%>
<html>
<body>
<center>
<s:form action="borrowBook.action">
<table>
<tr>
<th>序号</th>
<th>书号</th>
<th>书名</th>
<th>用户</th>
</tr>
<s:iterator value="abook" status="st" >
<!-- 隐藏域 得到 用户的id -->
<input type="hidden" name="bookId" value="<s:property value="id"/>" >
<!-- 此处 写一个隐藏域,name为bookId 要想将该值(在提交表单时)传给 对应的action 应该在目标action中 定义一个属性 为 bookId 也就是hidden 中 name 的值! (private Long bookId;)并且也提供get/set方法-->
<tr>
<td><s:property value="#st.count"/></td>
<td><s:property value="book.bno"/></td>
<td><s:property value="bname"/></td>
<td>
<s:select name="userId"
list="userNames"
listKey="id"
listValue="uname"
id="selectid"
emptyOption="-1"
headerValue="选择用户"
></s:select>
</td>
</tr>
</s:iterator>
</table>
<s:submit value="提交"></s:submit>
</s:form>
<input type="button" value="submit" onclick="get()"/>
</center>
</body>
</html>
action:类:
public class BookAction{
private Long bookId;
/**
此处的bookId必须和jsp页面的要传向Action的 值的name 值相同
*/
public Long getBookId() {
return bookId;
}
public void setBookId(Long bookId) {
this.bookId = bookId;
}
public String borrowBook(){
System.out.println("JSP bookId: "+bookId);
}
}