2 llx347246532 llx347246532 于 2016.03.08 19:03 提问

iframe 加载数据出现同事访问数据库后数据相同

现在第一项和第五项数据时一样的。请大神帮我看下这个应该怎么改。(使用bootstrap框架)

web.xml

 <servlet>
      <servlet-name>TrendChart</servlet-name>
      <servlet-class>web.TrendChartServlet</servlet-class>
   </servlet>
    <servlet-mapping>
      <servlet-name>TrendChart</servlet-name>
      <url-pattern>/trendchart</url-pattern>
   </servlet-mapping>

jquery tab所在页面,下面使用iframe将每一项镶嵌进一个块中

 <div id="tabs">
                        <ul>
                            <%if((dev_type == comm_info.DEV_TYPE_BARN_CO2)||(dev_type == comm_info.DEV_TYPE_BARN_TMP))
                            {%>
                            <li><a class="corner-tl" href="#tabs-1">空气温湿度曲线图</a></li>
                            <%}else
                            {%>
                            <li><a class="corner-tl" href="#tabs-1">实时水温、溶氧曲线图</a></li>
                            <%} %>
                            <%if((dev_type != comm_info.DEV_TYPE_BARN_CO2)&&(dev_type != comm_info.DEV_TYPE_BARN_TMP))
                            {%>
                            <li><a class="" href="#tabs-3">参数配置</a></li>
                            <li><a class="" href="#tabs-4">时段配置</a></li>
                            <%} %>
                            <li><a class="corner-tr" href="#tabs-5">事件查询</a></li>
                            <%if(dev_type == comm_info.DEV_TYPE_FISH_PH)
                            {%>
                            <li><a class="corner-tr" href="#tabs-6">PH、氨氮曲线图</a></li>
                            <%}%>
                            <%if(dev_type == comm_info.DEV_TYPE_BARN_CO2)
                            {%>
                            <li><a class="corner-tr" href="#tabs-7">土壤温湿度曲线图</a></li>
                            <li><a class="corner-tr" href="#tabs-8">二氧化碳曲线图</a></li>
                            <%}%>
                      </ul>
                        <%if((dev_type == comm_info.DEV_TYPE_BARN_CO2)||(dev_type == comm_info.DEV_TYPE_BARN_TMP))
                        {%>
                        <div id="tabs-1">
                            <p>
                                <iframe src="/trendchart?dev_id=<%=dev_id%>&date=<%=date %>&dev_type=<%=dev_type%>&var_type=2" width="100%" style="min-height:450px; height:100%"  ></iframe>
                            </p>
                        </div>
                        <%}else
                        {%>
                        <div id="tabs-1">
                            <p>
                                <!--iframe src="/fish_web/trendchart?dev_id=<%=dev_id%>&date=<%=date %>&dev_type=<%=dev_type%>&var_type=1" id="iframepage" onLoad="iFrameHeight()" width="100%" ></iframe-->
                                <iframe src="/trendchart?dev_id=<%=dev_id%>&date=<%=date %>&dev_type=<%=dev_type%>&var_type=1" width="100%"  style="min-height:450px; " id="myframe"  selected="true"></iframe>
                            </p>
                        </div>
                        <%} %>
                        <% 
                        if ((user_type != comm_info.USER_TYPE_AGENT_CHILD ) && (dev_type != comm_info.DEV_TYPE_BARN_CO2)&& (dev_type != comm_info.DEV_TYPE_BARN_TMP))
                        {%>
                        <div id="tabs-3">
                            <p>

                                <iframe src=a"/syscfg?dev_id=<%=dev_id%>&dev_type=<%=dev_type%>" width="100%" style="min-height:300px; height:100%"></iframe>

                            </p>
                        </div>
                        <div id="tabs-4">
                            <p>
                                <iframe src="/timecfg?dev_id=<%=dev_id%>&" width="100%" style="min-height:500px; height:100%"></iframe>
                            </p>
                      </div>
                      <% }%>
                     <div id="tabs-5">  
                     <p>
                        <iframe src="/eventqry?dev_id=<%=dev_id%>&date=<%=date %>" width="100%" style="min-height:350px; height:100%"></iframe>
                     </p>
                    </div> 
                    <%if(dev_type == comm_info.DEV_TYPE_FISH_PH)
                    {%>
                     <div id="tabs-6">  
                     <p>
                        <iframe src="/trendchart?dev_id=<%=dev_id%>&date=<%=date %>&dev_type=<%=dev_type%>&var_type=3" width="100%" style="min-height:450px; height:100%"></iframe>
                     </p>
                    </div> 
                    <%}%>
                    <%if(dev_type == comm_info.DEV_TYPE_BARN_CO2)
                    {%>
                     <div id="tabs-7">  
                     <p>
                        <iframe src="/trendchart?dev_id=<%=dev_id%>&date=<%=date %>&dev_type=<%=dev_type%>&var_type=4" width="100%" style="min-height:450px; height:100%"></iframe>
                     </p>
                    </div> 
                    <%}%>
                    <%if(dev_type == comm_info.DEV_TYPE_BARN_CO2)
                    {%>
                     <div id="tabs-8">  
                     <p>
                        <iframe src="/trendchart?dev_id=<%=dev_id%>&date=<%=date %>&dev_type=<%=dev_type%>&var_type=5" width="100%" style="min-height:450px; height:100%"></iframe>
                     </p>
                    </div> 
                    <%}%>

TrendChartServlet.java主要代码

  protected void doGet(HttpServletRequest req, HttpServletResponse resp) 
    throws ServletException, IOException {

       String dev_id = req.getParameter("dev_id");

       String date = "2016-01-06";
       int dev_type = Byte.parseByte(req.getParameter("dev_type"));
       int var_type = Byte.parseByte(req.getParameter("var_type"));

       DateFormat date_format = new SimpleDateFormat("yyyy-MM-dd");        
       if(dev_id != null)
       {
           req.setAttribute("dev_id", dev_id);


           //get his data
           dev_his_data his_data = new dev_his_data();
           int i = 0;
           try {
            his_data.date_s = date;
            his_data.date =   date_format.parse(date);

        } catch (ParseException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();

        }
           try {
               //logger.debug("get his data");
            dev_his_data.db2_get_history_info_sel(his_data, dev_id,  0, dev_type, var_type);
           } catch (SQLException e) {
            // TODO Auto-generated catch block
               //logger.debug(e);
           }

           try {
               dev_his_data.db2_get_history_info_sel(his_data, dev_id,  1, dev_type, var_type);
           } catch (SQLException e) {

           }
           try {
               dev_his_data.db2_get_history_info_sel(his_data, dev_id,  2, dev_type, var_type);
           } catch (SQLException e) {

           }
           try {
               dev_his_data.db2_get_history_info_sel(his_data, dev_id,  3, dev_type, var_type);
           } catch (SQLException e) {

           }

           req.setAttribute("his_data", his_data);
           req.setAttribute("dev_type", dev_type);
           req.setAttribute("var_type", var_type);
           jsp.forward(req, resp); 
       }

    }

dev_his_data.java主要代码

  public static  byte db2_get_history_info_sel(dev_his_data his_data, String dev_id ,int date_index, int dev_type, int var_type) throws SQLException 
    {       Connection conn=null;
        java.sql.CallableStatement cstmt = null;

        try
        {
        conn = DataAccessObject.dataSource.getConnection();

        if(conn.isClosed()) 
        {

            //logger.debug("failed connecting to the Database!");
            return -1;
        }
        cstmt = conn.prepareCall("{call get_history_qry_info(?,?,?,?,?,?)}");
        cstmt.setString(1, dev_id);
        java.sql.Date date= new java.sql.Date(0);
        date.setYear(his_data.date.getYear());
        date.setMonth(his_data.date.getMonth());
        date.setDate(his_data.date.getDate());
        cstmt.setDate(2,  date);
        cstmt.setInt(3, date_index);
        cstmt.setInt(4, dev_type);
        cstmt.setInt(5, var_type);
        cstmt.registerOutParameter(6, Types.VARCHAR);  

        cstmt.executeQuery();
        String out = cstmt.getString(6);
        String[] var=out.split(",");
        int time_interval_cnt = his_data.HISTORY_DATA_MAX_NUM/4;
        int cnt = (date_index*time_interval_cnt);
        for(int i=0; i<time_interval_cnt; i++)
        {
            his_data.history_data_item[cnt].tmp =Short.valueOf(var[i*3+1]);

            his_data.history_data_item[cnt].oxygen = Short.valueOf(var[i*3+2]);
            if((dev_type == comm_info.DEV_TYPE_BARN_CO2)&&(var_type== 5))

            {
                his_data.history_data_item[cnt].tmp *= 10;
            }
            his_data.history_data_item[cnt].validate = Byte.valueOf(var[i*3+0]);

            cnt+=1;
        }

        }
        finally
        {
            DataAccessObject.close(null, cstmt, conn);
        }
        return 0;
    }   

现在的问题是整个页面出来的时候1和5 全部加载完毕,但是读到的数据 都是5的,怎么解决呢。求指点。

1个回答

WinsenJiansbomber
WinsenJiansbomber   2016.03.08 22:15

你应该把这么长的代码分割成小块的,测试每个小块是不是都正常工作!

llx347246532
llx347246532 不知道,前者是这样做的。
接近 2 年之前 回复
WinsenJiansbomber
WinsenJiansbomber 为何不用AJAX,这是加载数据的最佳途径了
接近 2 年之前 回复
llx347246532
llx347246532 现在我的逻辑是在页面初始化的时候把数据都加在近来,然后iframe是异步加载数据,所以出错了。我需要同步执行。
接近 2 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!