| ad5081d3  孙向锦
 
初始化项目 | 1
2
3 |   package com.fh.util;
  
  import java.io.BufferedReader;
 | 
| 338594c8  孙向锦
 
添加教师端页面 | 4 |   import java.io.InputStreamReader;
 | 
| ad5081d3  孙向锦
 
初始化项目 | 5
6
7
8
9
10
11
12
13
14 |   import java.io.Reader;
  import java.util.Collection;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Map;
  import java.util.Set;
  
  import javax.servlet.http.HttpServletRequest;
  
  import com.alibaba.druid.proxy.jdbc.ClobProxyImpl;
 | 
| 338594c8  孙向锦
 
添加教师端页面 | 15 |   import com.alibaba.fastjson.JSONObject;
 | 
| ad5081d3  孙向锦
 
初始化项目 | 16
17
18
19
20
21
22 |   public class PageData extends HashMap implements Map{
  	
  	private static final long serialVersionUID = 1L;
  	
  	Map map = null;
  	HttpServletRequest request;
  	public PageData(HttpServletRequest request){
 | 
| 338594c8  孙向锦
 
添加教师端页面 | 23 |    		this.request = request;
 | 
| ad5081d3  孙向锦
 
初始化项目 | 24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 |   		Map properties = request.getParameterMap();
  		Map returnMap = new HashMap(); 
  		Iterator entries = properties.entrySet().iterator(); 
  		Map.Entry entry; 
  		String name = "";  
  		String value = "";  
  		while (entries.hasNext()) {
  			entry = (Map.Entry) entries.next(); 
  			name = (String) entry.getKey(); 
  			Object valueObj = entry.getValue(); 
  			if(null == valueObj){ 
  				value = ""; 
  			}else if(valueObj instanceof String[]){ 
  				String[] values = (String[])valueObj;
  				for(int i=0;i<values.length;i++){ 
  					 value = values[i] + ",";
  				}
  				value = value.substring(0, value.length()-1); 
  			}else{
  				value = valueObj.toString(); 
  			}
 | 
| b980d59d  孙向锦
 
修改模板 | 45 |   			returnMap.put(name.toUpperCase(), value); 
 | 
| ad5081d3  孙向锦
 
初始化项目 | 46 |   		}
 | 
| 338594c8  孙向锦
 
添加教师端页面 | 47
48
49
50
51
52
53
54
55
56
57
58
59 |           try {  
              BufferedReader streamReader = new BufferedReader( new InputStreamReader(request.getInputStream(), "UTF-8"));  
              StringBuilder responseStrBuilder = new StringBuilder();  
              String body = "";  
              while ((body = streamReader.readLine()) != null){
              	responseStrBuilder.append(body);  
              }
              if(!returnMap.containsKey("JSON")){
              	returnMap.put("JSON",responseStrBuilder.toString());
              }
          } catch (Exception e) {  
              e.printStackTrace();  
          }  
 | 
| ad5081d3  孙向锦
 
初始化项目 | 60
61
62
63
64
65
66 |   		map = returnMap;
  	}
  	
  	public PageData() {
  		map = new HashMap();
  	}
  	
 | 
| 338594c8  孙向锦
 
添加教师端页面 | 67
68
69
70
71
72
73
74
75
76 |   
  	public String getJsonString(){
  		Object obj = "";
  		if(map != null){
  			 obj = map.get("JSON");
  		}
  		
  		return obj.toString() ;
  	}
  	
 | 
| ad5081d3  孙向锦
 
初始化项目 | 77
78
79
80
81
82
83
84
85
86
87
88
89 |   	@Override
  	public Object get(Object key) {
  		Object obj = null;
  		if(map.get(key) instanceof Object[]) {
  			Object[] arr = (Object[])map.get(key);
  			obj = request == null ? arr:(request.getParameter((String)key) == null ? arr:arr[0]);
  		} else {
  			obj = map.get(key);
  		}
  		return obj;
  	}
  	
  	public String getString(Object key) {
 | 
| 066f7673  孙向锦
 
修复bug | 90
91
92
93
94 |   		Object obj = get(key);
  		if(obj != null){
  			return obj.toString();
  		}
  		return "";
 | 
| ad5081d3  孙向锦
 
初始化项目 | 95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170 |   	}
  	
  	@SuppressWarnings("unchecked")
  	@Override
  	public Object put(Object key, Object value) {
  		if(value instanceof ClobProxyImpl){ 			//读取oracle Clob类型数据
  			try {
  				ClobProxyImpl cpi = (ClobProxyImpl)value;
  				Reader is = cpi.getCharacterStream(); 	//获取流
  				BufferedReader br = new BufferedReader(is);
  				String str = br.readLine();
  				StringBuffer sb = new StringBuffer();
  				while(str != null){						//循环读取数据拼接到字符串
  					sb.append(str);
  					sb.append("\n");
  					str = br.readLine();
  				}
  				value = sb.toString();
  			} catch (Exception e) {
  				e.printStackTrace();
  			}
  		}
  		return map.put(key, value);
  	}
  	
  	@Override
  	public Object remove(Object key) {
  		return map.remove(key);
  	}
  
  	public void clear() {
  		map.clear();
  	}
  
  	public boolean containsKey(Object key) {
  		// TODO Auto-generated method stub
  		return map.containsKey(key);
  	}
  
  	public boolean containsValue(Object value) {
  		// TODO Auto-generated method stub
  		return map.containsValue(value);
  	}
  
  	public Set entrySet() {
  		// TODO Auto-generated method stub
  		return map.entrySet();
  	}
  
  	public boolean isEmpty() {
  		// TODO Auto-generated method stub
  		return map.isEmpty();
  	}
  
  	public Set keySet() {
  		// TODO Auto-generated method stub
  		return map.keySet();
  	}
  
  	@SuppressWarnings("unchecked")
  	public void putAll(Map t) {
  		// TODO Auto-generated method stub
  		map.putAll(t);
  	}
  
  	public int size() {
  		// TODO Auto-generated method stub
  		return map.size();
  	}
  
  	public Collection values() {
  		// TODO Auto-generated method stub
  		return map.values();
  	}
  	
  }
 |