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);
        }



    }
  • 相关阅读:
    Vue 封装js 并 引用
    Vue todolist练习 知识点
    Vue 双向数据绑定、事件介绍以及ref获取dom节点
    Vue 目录结构 绑定数据 绑定属性 循环渲染数据
    Vue自学笔记--项目的创建
    sqlalchemy第一部分
    mysql查询补充
    mysql数据库查询操作
    mysql数据库关系操作
    数据表的约束及数据类型操作
  • 原文地址:https://www.cnblogs.com/a1280055207/p/3219961.html
Copyright © 2011-2022 走看看