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版本存在中文请求参数乱码,可以自己添加过滤器;




  • 相关阅读:
    文档_word常用设置-操作
    Java NIO总结 整理
    Spring缓存注解@Cacheable、@CacheEvict、@CachePut使用
    Lock和synchronized比较详解
    SpringBoot如何将类中属性与配置文件中的配置进行绑定
    简述MyBatis的一级缓存、二级缓存原理
    服务器端filter解决ajax简单请求跨域访问问题
    Spring Boot异步执行程序
    程序猿和hr面试时的巅峰对决
    数据库三大范式详解(通俗易懂)
  • 原文地址:https://www.cnblogs.com/zmpandzmp/p/3649027.html
Copyright © 2011-2022 走看看