将 jsp 页面的值 传到struts2 action中

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" οnclick="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);
}


}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值