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



    }
  • 相关阅读:
    GLUT Tutorials 9: GLUT子菜单
    GLUT Tutorials 8: GLUT菜单
    GLUT Tutorials 9: GLUT鼠标
    GLUT Tutorials 8: GLUT高级键盘控制
    GLUT Tutorials 7: GLUT高级键盘控制
    GLUT Tutorials 6: GLUT场景漫游
    gif 录制小工具
    GLUT Tutorials 5: GLUT键盘控制
    java 传址或传值
    java中如何将byte[]里面的数据转换成16进制字符串
  • 原文地址:https://www.cnblogs.com/a1280055207/p/3219961.html
Copyright © 2011-2022 走看看