1. Butuh dua paket: jdom.jar dan rome.jar.
2. Buat proyek, dan konten web.xml adalah sebagai berikut:
Salinan kode adalah sebagai berikut:
<? Xml Version = "1.0" encoding = "UTF-8"?>
<versi web-app = "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 ">
<creendy-file-list>
<creendaking-file> index.jsp </celcome-file>
</celcome-file-list>
</web-app>
3. Buat konten index.jsp sebagai berikut:
Salinan kode adalah sebagai berikut:
Salin kode sebagai berikut
<%@page contentType = "Teks/html"%>
<%@pageEncoding = "UTF-8"%>
<Html>
<head>
<meta http-equiv = "konten tipe" content = "text/html; charset = utf-8">
<title> SINA News </iteme>
</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 ("agen pengguna",
</p> </p> </p> </p> "mozilla/4.0 (kompatibel; msie 5.0; windows nt; digext)");
</p> </p> com.sun.syndication.io.syndfeedInput input = com.sun.syndication.io.syndfeedInput ();
</p> </p> com.sun.syndication.feed.synd.syndfeed feed = input.build (com.sun.syndication.io.xmlreader baru (feedUrl));
</p>%>
</p> <div align = "center">
</p> </p> <h1> <%= feed.gettitle ()%> </h1>
</p> </p> <Border Table = 1 CellPadding = 3>
</p> </p> </p> <tr>
</p> </p> </p> </p> <th> Nomor </th>
</p> </p> </p> </p> <th> judul </th>
</p> </p> </p> </p> <th> waktu www.vevb.com </th>
</p> </p> </p> </p> <t th> konten </th>
</p> </p> </p> </tr>
</p> </p> </p> <%
</p> </p> </p> </p> java.util.list list = feed.getEntries ();
</p> </p> </p> </p> untuk (int i = 0; i <list.size (); i ++) {
</p> </p> </p> </p> com.sun.syndication.feed.synchrond.syndentry entri = (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> </able>
</p> </div>
</p> <br>
</body>
</html>