• Html前面多次请求状态码为200,均能获取数据,但是往后面多请求几次,状态码会变成 pending,这是为什么,麻烦大神指导


    1、做的是一个 三联下拉框,并通过最后一个下拉框显示出员工信息。

       -    这是请求正确的界面

      -    这是经过多次请求后会出现问题

      

    2. 环境用的是 Spring、Struts2、Hibernate,通过实体类映射创建表,通过 原生SQL查询出的数据,用JSON数据格式返回。

      -    实体类

    package com.itcat.entity;
    
    public class Location {
        
        private Integer location_id;
        private String city;
        
        public Integer getLocation_id() {
            return location_id;
        }
        public void setLocation_id(Integer location_id) {
            this.location_id = location_id;
        }
        public String getCity() {
            return city;
        }
        public void setCity(String city) {
            this.city = city;
        }
        
    }

      -    映射文件

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC 
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
        
    <hibernate-mapping>
         <class name="com.itcat.entity.Location" table="locations">
            <id name="location_id" column="location_id">
                <generator class="native"></generator>
            </id>
            <property name="city" column="city"></property>
        </class>
    </hibernate-mapping>

      -    Struts配置文件

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE struts PUBLIC
        "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
        "http://struts.apache.org/dtds/struts-2.3.dtd">
        
    <struts>
        <package name="root" namespace="/" extends="json-default">
            <action name="findByCity" class="com.itcat.action.UserAction" method="findByCityInfo">
                <result name="SUCCESS" type="json"></result>
            </action>
    
        </package>
    </struts>

      -    DaoImpl方法

       public List<Location> findByCity() {
            List<Location> list = null;
            try {
                String sql = "SELECT " + 
                             "l.location_id," + 
                             "l.city " + 
                             "FROM " + 
                             "locations l";
                SessionFactory sf = hibernateTemplate.getSessionFactory();
                Session session=sf.openSession();
                Query query = session.createSQLQuery(sql).addEntity(Location.class);
                list = query.list();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return list;
        }

      -    action类

        public String findByCityInfo() {
            List<Location> list = warterService.findByCity();
            try {
                this.result = mapper.writeValueAsString(list);
            } catch (Exception e) {
                e.printStackTrace();
            }
            return "SUCCESS";
        }

    经过十分钟仔细的查看和调试,发现session没有关闭,session.close()之后,问题没有了。

  • 相关阅读:
    java解析xml
    支持向量机SVM
    资源-菜单
    GIT
    基于OpenCV的图书扫描识别程序开发
    最大公约数(gcd)还有最小公倍数(lcm)的共通之处
    python网页分析
    python爬虫的基本知识储备
    大数加法 (A + B Problem II)
    Andy's First Dictionary (set)
  • 原文地址:https://www.cnblogs.com/LionsEyes/p/8875778.html
Copyright © 2020-2023  润新知