posts - 0, comments - 77, trackbacks - 0, articles - 356
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

ajax struts url stream

Posted on 2007-07-04 11:54 semovy 阅读(355) 评论(0)  编辑  收藏 所属分类: struts

public class Example7Action extends Action {


  public ActionForward execute(ActionMapping mapping, ActionForm inForm, HttpServletRequest request, HttpServletResponse response) throws Exception {

    String feedURL = (String)request.getParameter("feedURL");

    if (feedURL == null || feedURL.equalsIgnoreCase("")) {
      return null; // Trivial error handling... if no URL sent in, essentially do nothing
    }
    feedURL = new URLCodec().decode(feedURL);

    // Go get the feed
    StringBuffer xml = new StringBuffer(4096);
    try {
      URL               u   = new URL(feedURL);
      InputStream       in  = u.openStream();
      InputStreamReader isr = new InputStreamReader(in);
      BufferedReader    br  = new BufferedReader(isr);
      String theLine;
      while ((theLine = br.readLine()) != null) {
        xml.append(theLine);
      }
    } catch (Exception e) {
      System.err.println("Example7Action Exception: " + e);
    }

    // Write the XML to response
    response.setContentType("text/xml");
    PrintWriter out = response.getWriter();
    out.println(xml);
    out.flush();

    return null;

  } // End execute()


}


只有注册用户登录后才能发表评论。


网站导航: