zoukankan      html  css  js  c++  java
  • 异步发送表单数据到JavaBean,并响应JSON文本返回

    1)  提交表单后,将JavaBean信息以JSON文本形式返回到浏览器

    <form>
            编号:<input type="text" name="id" value="1"/><br/>
            姓名:<input type="text" name="name" value="哈哈"/><br/>
            薪水:<input type="text" name="sal" value="5000"/><br/>
            <input type="button" value="异步提交注册"/>
        </form>
        
        <script type="text/javascript">
            $(":button").click(function(){
                var url = "${pageContext.request.contextPath}/user/add.action";
                var sendData = {
                    "id":1,
                    "name":"哈哈",
                    "sal":5000
                };
                $.post(url,sendData,function(backData,textStatus,ajax){
                    alert(ajax.responseText);
                });
            });
        </script>
    public class User {
        private Integer id;
        private String name;
        private Double sal;
        public User(){}
        public Integer getId() {
            return id;
        }
        public void setId(Integer id) {
            this.id = id;
        }
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public Double getSal() {
            return sal;
        }
        public void setSal(Double sal) {
            this.sal = sal;
        }
    }
    @Controller
    @RequestMapping(value="/user")
    public class UserAction {
    
        @RequestMapping(value="/add")
        public @ResponseBody User add(User user) throws Exception{
            System.out.println(user.getId()+":"+user.getName()+":"+user.getSal());
            return user;
        }
        
    }

    spring.xml

     <!-- Action控制器 -->
          <context:component-scan base-package="loaderman.javaee.springmvc.app25"/>      
    
    
            <!-- 配适器 -->
          <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
                  <property name="messageConverters">
                         <list>
                          <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/>
                         </list>
                  </property>
          </bean>
  • 相关阅读:
    ORA-01439: column to be modified must be empty to change datatype
    解决rhel相关系统下yum找不到安装包的解决方法
    oracle的function和procedure返回值给shell
    [摘] SQLPLUS Syntax
    Unix/Linux中shell调用sqlplus的方式
    sqlplus连接数据库的4种方式
    shell调用sqlplus批量执行sql文件
    shell自定义函数
    Java创建Oracle数据库表
    TCP的三次握手(建立连接)和四次挥手(关闭连接)
  • 原文地址:https://www.cnblogs.com/loaderman/p/10063349.html
Copyright © 2011-2022 走看看