zoukankan      html  css  js  c++  java
  • html------3.javaWeb网页下拉列表框调用数据库数据

    效果

    struts+action+jsp

    1创建实体:实现 get set方法

     2、action

    调用api 接口 处理json 数据

    api调用处理

    package com.util;
    
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.net.URLConnection;
    
    import net.sf.json.JSONArray;
    import net.sf.json.JSONObject;
    
    import com.google.gson.JsonIOException;
    import com.google.gson.JsonSyntaxException;
    /**
     * 接收url 并处理 json 数据
     * @author Administrator
     *
     */
    public class UrlUtil {
        
        private static String LINKURL="http://localhost:8080/";
        
        public static String getUrl(String url)
        {
            String resData = null;
            StringBuffer s = new StringBuffer();
            BufferedReader bReader = null;
            try {
                
                URL urlWeb = new URL(LINKURL+url);
                URLConnection connection = urlWeb.openConnection();
                bReader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8"));
                while (null != (resData = bReader.readLine())) {
                    s.append(resData);
                }
                bReader.close();
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            System.out.println(s);
            return s.toString();
        }
        
        public static void main(String[] args) {
            //测试请求的 json 数据
            //System.out.println(getUrl("rubOrder.action?wor_id=5&order_id=100"));
            String s=getUrl("rubOrderRoom.action?wor_id=3&is_system=0");
            try {
                //net.sf.json.jsonobject 没有 new JSONObject(String)的构造方法
                JSONObject json = JSONObject.fromObject(s.toString());
                
                //success
                //Boolean data=(Boolean) json.get("success");
                
                String data=json.getString("data");
                System.out.println(data);
                JSONObject jsonData=JSONObject.fromObject(data);
                
                
                System.out.println(jsonData.get("data").toString());
                //String str = "[{name:'a',value:'aa'},{name:'b',value:'bb'},{name:'c',value:'cc'},{name:'d',value:'dd'}]" ;  // 一个未转化的字符串
                JSONArray bjson = JSONArray.fromObject(jsonData.get("data").toString() ); // 首先把字符串转成 JSONArray  对象
                if(bjson.size()>0){
                    for(int i=0;i<bjson.size();i++){
                        JSONObject job = bjson.getJSONObject(i);  // 遍历 jsonarray 数组,把每一个对象转成 json 对象
                        System.out.println(job.get("problem_description")+"****"+job.get("order_id")) ;  // 得到 每个对象中的属性值
                    }
                }
            } catch (JsonIOException e) {
                e.printStackTrace();
            } catch (JsonSyntaxException e) {
                e.printStackTrace();
            }
        }
    }

    struts.xml配置

     

    jsp页面数据列表显示

    点击按钮提交数据

     struts.xml配置

    action处理数据

  • 相关阅读:
    APP测试-流量测试
    APP测试-流畅度测试
    APP测试-耗电分析
    工具安装-Homebrew
    工具安装-go for Mac
    APP测试-耗电量测试
    APP测试-CPU测试
    APP测试-内存测试
    APP测试-monkey
    APP测试-adb命令
  • 原文地址:https://www.cnblogs.com/coriander/p/6708602.html
Copyright © 2011-2022 走看看