zoukankan      html  css  js  c++  java
  • 7、请求参数接收

    1. 对与请求参数,可以在所请求的action中添加相应的属性,写出get和set方法,在表单中配置name属性与action中属性的名称一致,提交到所在action即可;如下:

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      public class HelloWorldAction {

          private String name;
          private int id;

          public String getName() {
              return name;
          }
       
          public void setName(String name) {

              this.name = name;
          }
       
          public int getId() {
              return id;
          }
       
          public void setId(int id) {
              this.id = id;
          }
      }

      则index.jsp中表单中应如下(对应属性名一致):

      1
      2
      3
      4
      5
      <form action="${pageContext.request.contextPath }/control/department/list_execute.action" method="post">

                  
      <input type="text" name="id"><br>
                  <input type="text" name="name"><br>
                  <input type="submit" value="提交">
      </form>
      获取值:
      1
      2
      ${id }</br>
      ${name }

    2. 对于复杂请求参数(以对象封装,实际应用如此;Person类必须使用默认构造器,不能自己添加构造器):

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      public class HelloWorldAction {

              private Person person;
       
              public Person getPerson() {
              
      return person;
          }
       
          public void setPerson(Person person) {
             
       this.person = person;
          }
      }

      则表单如下:

      1
      2
      3
      4
      5
      <form action="${pageContext.request.contextPath }/control/department/list_execute.action" method="post">


                  <input type="text" name="person.id"><br>
                 
       <input type="text" name="person.name"><br>
               
         <input type="submit" value="提交">
              </form>

      获取的值的方法如下:

      1
      2
      ${person.id }</br>
      ${person.name }
    3. struts2.1.6版本存在中文请求参数乱码,可以自己添加过滤器;




  • 相关阅读:
    hdu 4027 Can you answer these queries?
    hdu 4041 Eliminate Witches!
    hdu 4036 Rolling Hongshu
    pku 2828 Buy Tickets
    hdu 4016 Magic Bitwise And Operation
    pku2886 Who Gets the Most Candies?(线段树+反素数打表)
    hdu 4039 The Social Network
    hdu 4023 Game
    苹果官方指南:Cocoa框架(2)(非原创)
    cocos2d 中 CCNode and CCAction
  • 原文地址:https://www.cnblogs.com/zmpandzmp/p/3649027.html
Copyright © 2011-2022 走看看