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()
}