java中rss解析器(rome.jar和jdom.jar)示例
1.需要 jdom.jar 和 rome.jar 這兩個(gè)包。
2.創(chuàng)建一個(gè)項(xiàng)目,web.xml的內(nèi)容如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
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">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
3.創(chuàng)建一個(gè)index.jsp 內(nèi)容如下:
代碼如下 復(fù)制代碼
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Sina News</title>
</head>
<body>
</p><%
</p></p>java.util.Properties systemSettings = System.getProperties();
</p></p>systemSettings.put("http.proxyHost", "mywebcache.com");
</p></p>systemSettings.put("http.proxyPort", "8080");
</p></p>System.setProperties(systemSettings);
</p></p>String urlStr = "http://rss.sina.com.cn/news/marquee/ddt.xml";
</p></p>java.net.URLConnection feedUrl = new java.net.URL(urlStr).openConnection();
</p></p>feedUrl.setRequestProperty("User-Agent",
</p></p></p></p>"Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
</p></p>com.sun.syndication.io.SyndFeedInput input = new com.sun.syndication.io.SyndFeedInput();
</p></p>com.sun.syndication.feed.synd.SyndFeed feed = input.build(new com.sun.syndication.io.XmlReader(feedUrl));
</p>%>
</p><div align="center">
</p></p><h1><%=feed.getTitle()%></h1>
</p></p><table border=1 cellpadding=3 width="700">
</p></p></p><tr>
</p></p></p></p><th>Number</th>
</p></p></p></p><th>Title</th>
</p></p></p></p><th>Time www.dhdzp.com</th>
</p></p></p></p><th>Content</th>
</p></p></p></tr>
</p></p></p><%
</p></p></p></p>java.util.List list = feed.getEntries();
</p></p></p></p>for (int i = 0; i < list.size(); i++) {
</p></p></p></p></p>com.sun.syndication.feed.synd.SyndEntry entry = (com.sun.syndication.feed.synd.SyndEntry) list.get(i);
</p></p></p></p>%>
</p></p></p><tr>
</p></p></p></p><td><%=i + 1%></td>
</p></p></p></p><td><a href="<%=entry.getLink()%>"><%=entry.getTitle()%></a></td>
</p></p></p></p><td><%=entry.getPublishedDate()%></td>
</p></p></p></p><td><%=entry.getDescription().getValue() %></td>
</p></p></p></tr>
</p></p></p><%
</p></p></p></p>}
</p></p></p>%>
</p></p></table>
</p></div>
</p><br>
</body>
</html>
相關(guān)文章
如何使用SpEL表達(dá)式實(shí)現(xiàn)動(dòng)態(tài)分表查詢(xún)
這篇文章主要介紹了如何使用SpEL表達(dá)式實(shí)現(xiàn)動(dòng)態(tài)分表查詢(xún),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-12-12
JSP 獲取spring容器中bean的兩種方法總結(jié)
這篇文章主要介紹了JSP 獲取spring容器中bean的方法總結(jié)的相關(guān)資料,需要的朋友可以參考下2017-05-05
Springboot 整合RabbitMq(用心看完這一篇就夠了)
這篇文章主要介紹了Springboot 整合RabbitMq(用心看完這一篇就夠了),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-12-12
運(yùn)行Springboot測(cè)試類(lèi)查詢(xún)數(shù)據(jù)庫(kù)數(shù)據(jù)顯示白網(wǎng)頁(yè)問(wèn)題及解決方法
Spring Boot應(yīng)用未能啟動(dòng)的原因是它沒(méi)有找到合適的數(shù)據(jù)庫(kù)配置具體來(lái)說(shuō),它需要一個(gè)數(shù)據(jù)源(DataSource),但未能在你的配置中找出,也沒(méi)有找到任何嵌入式數(shù)據(jù)庫(kù)(H2, HSQL 或 Derby),本文給大家分享運(yùn)行Springboot測(cè)試類(lèi)查詢(xún)數(shù)據(jù)庫(kù)數(shù)據(jù)顯示白網(wǎng)頁(yè)問(wèn)題及解決方法,一起看看吧2023-11-11
springBoot項(xiàng)目配置文件加載優(yōu)先級(jí)及同配置覆蓋問(wèn)題詳解
SpringBoot配置?件可以放置在多種路徑下,不同路徑下的配置優(yōu)先級(jí)有所不同,下面這篇文章主要給大家介紹了關(guān)于springBoot項(xiàng)目配置文件加載優(yōu)先級(jí)及同配置覆蓋問(wèn)題的相關(guān)資料,需要的朋友可以參考下2023-05-05
Java如何向主函數(shù)main中傳入?yún)?shù)
這篇文章主要介紹了Java如何向主函數(shù)main中傳入?yún)?shù),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-02-02
JavaWeb JDBC + MySql 通訊錄實(shí)現(xiàn)簡(jiǎn)單的增刪改查功能案例詳解
這篇文章主要介紹了JavaWeb JDBC + MySql 通訊錄實(shí)現(xiàn)簡(jiǎn)單的增刪改查功能,結(jié)合具體案例形式詳細(xì)分析了JavaWeb JDBC + MySql數(shù)據(jù)庫(kù)連接、增刪改查等相關(guān)操作技巧與注意事項(xiàng),需要的朋友可以參考下2019-08-08

