java中rss解析器(rome.jar和jdom.jar)示例

这篇文章主要介绍了java中rss解析器(rome.jar和jdom.jar)示例,需要的朋友可以参考下

1.需要 jdom.jar 和 rome.jar 这两个包。
2.创建一个项目,web.xml的内容如下:

复制代码 代码如下:


         xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

   
        index.jsp
   


 

3.创建一个index.jsp 内容如下:

复制代码 代码如下:

 代码如下 复制代码
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>




Sina News

<%

java.util.Properties systemSettings = System.getProperties();

systemSettings.put("http.proxyHost", "mywebcache.com");

systemSettings.put("http.proxyPort", "8080");

System.setProperties(systemSettings);

String urlStr = "http://rss.sina.com.cn/news/marquee/ddt.xml";

java.net.URLConnection feedUrl = new java.net.URL(urlStr).openConnection();

feedUrl.setRequestProperty("User-Agent",

"Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");

com.sun.syndication.io.SyndFeedInput input = new com.sun.syndication.io.SyndFeedInput();

com.sun.syndication.feed.synd.SyndFeed feed = input.build(new com.sun.syndication.io.XmlReader(feedUrl));

%>


<%=feed.getTitle()%>








<%

java.util.List list = feed.getEntries();

for (int i = 0; i

com.sun.syndication.feed.synd.SyndEntry entry = (com.sun.syndication.feed.synd.SyndEntry) list.get(i);

%>







<%

}

%>

NumberTitleTime www.0133.cnContent
<%=i + 1%><%=entry.getTitle()%><%=entry.getPublishedDate()%><%=entry.getDescription().getValue() %>






以上就是java中rss解析器(rome.jar和jdom.jar)示例的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » Java