action端发请求并且处理
我们一般是在前端发请示,然后在struts的action端来处理请求。
如果有这样的需求,需要在action里得到某个“.do”请求的结果,这时候可以用流来解决。如下:
private String getHighWayAndMile(double x,double y,HttpServletRequest request){String serverName = request.getServerName();String serverPort = new Integer(request.getServerPort()).toString();String urlString = "http://"+serverName+":"+serverPort+"/gis_web/webmap/UtilAction.do"; String param = "tools=LATESTPOINT&x="+x+"&y="+y+"&IS_FOR_PHONE=1"; StringBuffer sb = new StringBuffer(); try { URL U = new URL(urlString+"?"+param); URLConnection connection = U.openConnection(); connection.connect(); BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); String line; while ((line = in.readLine())!= null){ sb.append(line); } in.close(); } catch (IOException e) {e.printStackTrace();} return sb.toString();}?