1. The jdom. jar and rome. jar packages are required.
2. Create a project. The content of web. xml is as follows:
The Code is as follows:
<? 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. Create an index. jsp with the following content:
The Code is as follows:
<% @ 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>
<%
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 ));
%>
<Div align = "center">
<H1> <% = feed. getTitle () %> <Table border = 1 cellpadding = 3 width = "700">
<Tr>
<Th> Number </th>
<Th> Title </th>
<Th> Time www.111cn.net </th>
<Th> Content </th>
</Tr>
<%
Java. util. List list = feed. getEntries ();
For (int I = 0; I <list. size (); I ++ ){
Com. sun. syndication. feed. synd. SyndEntry entry = (com. sun. syndication. feed. synd. SyndEntry) list. get (I );
%>
<Tr>
<Td> <% = I + 1%> </td>
<Td> <a href = "<% = entry. getLink () %>"> <% = entry. getTitle () %> </a> </td>
<Td> <% = entry. getPublishedDate () %> </td>
<Td> <% = entry. getDescription (). getValue () %> </td>
</Tr>
<%
}
%>
</Table>
</Div>
<Br>
</Body>
</Html>
4. Finished.
Rss reading package tool: http://share.weiyun.com/72ac26b22b846505dcc1e14a623abd8d
For more details, see: http://www.111cn.net/jsp/Java/58107.htm