去看下restful风格的方式,感觉很适合你这个需求。

解决方案 »

  1.   

    你返回html 解析也行阿。
    要么 定义webservice  android 直接请求也很爽。
      

  2.   

    现在我是这样写的,但是得不到作用域中的对象,仅仅得到解析后的html@Controller
    @RequestMapping("/restproxy")
    public class HttpController {
    /**
     * 默认post方法
     * @param systemClient 调用系统编号
     * @param url 调用地址 中间用!符号分割 如:index!get.thm
     * @param charset 编码格式 默认UTF-8
     * @param request
     * @param response
     * @param args  json格式的参数
     */
    @RequestMapping(value="/url/{url}")
    public void execute(@PathVariable("url") String actionMethod,HttpServletRequest request,HttpServletResponse response,String argsjson) {
    String action = actionMethod.split("_")[0];
    String method = actionMethod.split("_")[1];

    List<NameValuePair> nvps = new ArrayList<NameValuePair>();
    if(StringUtil.isNotBlank(argsjson)){
    JSONObject json = JSONObject.fromObject(argsjson);
    Iterator<?> it = json.keys();  
                while (it.hasNext()) {
                 String key = (String) it.next();  
                 nvps.add(new BasicNameValuePair(key, json.getString(key)));
                }  
    }

    String result = null;
    try {
    String url = "http://localhost:8080/PudongTravelWeb/page/"+action+"_"+method+".action";
    result = doPost(url, nvps, "UTF-8",0,0,false,request,response);
    } catch (ClientProtocolException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    System.out.println(result);
    }
    public static String doPost(String url, List<NameValuePair> nvps, String charset, int connectTimeout,
    int readTimeout, boolean isGzip,HttpServletRequest request,HttpServletResponse response) throws ClientProtocolException, IOException {
    DefaultHttpClient httpclient = new DefaultHttpClient();
    httpclient.getParams().setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT, connectTimeout);// 连接超时
    httpclient.getParams().setIntParameter(HttpConnectionParams.SO_TIMEOUT, readTimeout); // 读取超时
    if (isGzip) {
    httpclient.addRequestInterceptor(new RequestAcceptEncoding());
    httpclient.addResponseInterceptor(new ResponseContentEncoding());
    }
    try { HttpPost httpPost = new HttpPost(url);
    if(null==nvps){
    nvps=new ArrayList<NameValuePair>();
    }
    httpPost.setEntity(new UrlEncodedFormEntity(nvps, charset.toUpperCase()));
    ResponseHandler<String> responseHandler = new BasicResponseHandler();
    String restr=httpclient.execute(httpPost, responseHandler);
    return restr;
    } finally {
    httpclient.getConnectionManager().shutdown();
    }
    }
    }
      

  3.   

    http://localhost:8080/test/get/url/grab_search.json?args={inventoryId:1}这样访问,去掉struts,返回的不可能是页面了吧,之所以跳到页面,是应该你struts做了映射造成的。
      

  4.   

    PC端确实是使用struts并且配置了跳转页面,所以现在只想得到跳转中的数据,并不想得到跳转之后解析出来的html
      

  5.   

    你的dopost根本就没有封装json格式。
    response.setContentType("application/json");
    // Get the printwriter object from response to write the required json object to the output stream      
    PrintWriter out = response.getWriter();
    // Assuming your json object is **jsonObject**, perform the following, it will return your json object  
    out.print(jsonObject);
    out.flush();