JAvaはjson文字列を呼び出しページに戻してjsonとする
3267 ワード
@MethodResourceDesc(name = "[data] ")
@RequestMapping(value = "/data/realtimeQuoteListMarket.do")
@ResponseBody
public void realtimeQuoteListMarket(
HttpServletRequest request,HttpServletResponse response) throws IOException{
int quoteType = RequestHelper.getQueryFieldsInt(request, "quoteType");
String contractCode = RequestHelper.getQueryFields(request, "code");
final String url = "http://IP:10001/data/imsQuote/IndexNoKey.do?contractCode="+contractCode+""eType="+quoteType;
String strRet = HttpUtils.doGet(url);
response.setContentType("text/xml;charset=UTF-8");
OutputStream os = response.getOutputStream();
if(!"".equals(strRet) && strRet != null){
os.write(strRet.getBytes());
os.flush();
os.close();
}else{
JSONObject json = new JSONObject();
json.put("code", -1);
json.put("success", false);
json.put("message", null);
os.write(json.toString().getBytes());
os.flush();
os.close();
}
}
/**
*
*
* @param url
* @return
*/
public static String doGet(String url) {
HttpClientParams params = new HttpClientParams();
params.setParameter("name", "name");
String response = null;
HttpClient client = new HttpClient();
HttpMethod method = new GetMethod(url);
client.setParams(params);
HttpConnectionManagerParams managerParams = client.getHttpConnectionManager().getParams();
// ( )
managerParams.setConnectionTimeout(15000);
// ( )
managerParams.setSoTimeout(15000);
try {
client.executeMethod(method);
// if (method.getStatusCode() == HttpStatus.SC_OK) {
// response = method.getResponseBodyAsString();
// }
InputStream resStream = method.getResponseBodyAsStream();
BufferedReader br = new BufferedReader(new InputStreamReader(resStream));
StringBuffer resBuffer = new StringBuffer();
String resTemp = "";
while((resTemp = br.readLine()) != null){
resBuffer.append(resTemp);
}
response = resBuffer.toString();
}
catch (URIException e) {
logger.info(e.getMessage(), e);
return null;
}
catch (IOException e) {
logger.info(e.getMessage(), e);
}
finally {
method.releaseConnection();
}
return response;
}
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-51069946-1', 'iteye.com');
ga('send', 'pageview');