1. Benötigen Sie zwei Pakete: jdom.jar und rome.jar.
2. Erstellen Sie ein Projekt, und der Inhalt von web.xml ist wie folgt:
Die Codekopie lautet wie folgt:
<? xml Version = "1.0" coding = "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-Dateiliste>
<Welcome-File> Index.jsp </Welcome-File>
</Welcome-Dateiliste>
</web-App>
3. Erstellen Sie einen Index.jsp -Inhalt wie folgt:
Die Codekopie lautet wie folgt:
Kopieren Sie den Code wie folgt
<%@page contentType = "text/html"%>
<%@pageCoding = "utf-8"%>
<html>
<kopf>
<meta http-äquiv = "content-type" content = "text/html; charset = utf-8">
<title> SINA News </title>
</head>
<body>
</p> <%
</p> </p> java.util.properties systemettings = system.getProperties ();
</p> </p> systemettings.put ("http.proxyhost", "mywebcache.com");
</p> </p> systemettings.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 (kompatibel; 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> Nummer </th>
</p> </p> </p> </p> <Th> Titel </th>
</p> </p> </p> </p> <th> Zeit www.vevb.com </th>
</p> </p> </p> </p> <th> Inhalt </th>
</p> </p> </p> </tr>
</p> </p> </p> <%
</p> </p> </p> </p> java.util.list list = feed.getentries ();
</p> </p> </p> </p> für (int i = 0; i <list.size (); i ++) {
</p> </p> </p> </p> com.sun.Syndication.feed.synchrond.SyndEntry Eintrag = (com.sun.syndication.feed.synchrond.SynDentry) liste.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 = "<%= Eintrag.getLink ()%>"> <%= Eintrag.gettitle ()%> </a> </td>
</p> </p> </p> </p> <td> <%= Eintrag
</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>