1. Besoin de deux packages: JDom.jar et Rome.jar.
2. Créez un projet, et le contenu de web.xml est le suivant:
La copie de code est la suivante:
<? 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: ScheMalation = "http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd ">
<Welcome-File-list>
<Lelcome-File> index.jsp </venue-file>
</ Welcome-File-list>
</ web-app>
3. Créez un contenu index.jsp comme suit:
La copie de code est la suivante:
Copiez le code comme suit
<% @ page contentType = "text / html"%>
<% @ page Pageencoding = "UTF-8"%>
<html>
<adal>
<meta http-equiv = "contenu-type" contenu = "text / html; charset = utf-8">
<Title> Sina News </TITME>
</ 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> chaîne urlstr = "http://rs.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>
</p> </p> </p> <tr>
</p> </p> </p> </p> <th> Numéro </th>
</p> </p> </p> </p> <th> Title </th>
</p> </p> </p> </p> <th> Time www.vevb.com </th>
</p> </p> </p> </p> <th> Contenu </th>
</p> </p> </p> </tr>
</p> </p> </p> <%
</p> </p> </p> </p> java.util.list list = feed.getEntries ();
</p> </p> </p> </p> pour (int i = 0; i <list.size (); i ++) {
</p> </p> </p> </p> com.sun.syndication.feed.synchrond.synontry entrée = (com.sun.syndication.feed.synchrond.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>
</docy>
</html>