zoukankan      html  css  js  c++  java
  • 将 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" 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);
        }



    }
  • 相关阅读:
    一:多线程--多线程简单介绍
    五:网络--多线程断点下载
    四:网络--NSURLConnection基本使用
    三:网络--数据安全/加密
    二:网络--GET请求和POST请求
    一:网络--HTTP协议
    源代码管理工具GIT
    MyBatis 多参问题
    jquery 事件
    jquery点击事件
  • 原文地址:https://www.cnblogs.com/a1280055207/p/3219961.html
Copyright © 2011-2022 走看看