1. Precisa de dois pacotes: JDOM.JAR e ROMA.JAR.
2. Crie um projeto e o conteúdo do web.xml é o seguinte:
A cópia do código é a seguinte:
<? xml versão = "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 ">
<list-list>
<ldenmal-File> index.jsp </-Welcome-File>
</-Welcome-File-List>
</web-app>
3. Crie um conteúdo index.jsp da seguinte maneira:
A cópia do código é a seguinte:
Copie o código da seguinte forma
<%@página contenttype = "text/html"%>
<%@Page PageEncoding = "UTF-8"%>
<html>
<head>
<meta http-equiv = "content-type" content = "text/html; charset = utf-8">
<Title> Sina News </ititure>
</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 (compatível; 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> <borda da tabela = 1 CellPadding = 3>
</p> </p> </p> <tr>
</p> </p> </p> </p> <th> número </th>
</p> </p> </p> </p> <th> título </th>
</p> </p> </p> </p> <th> time www.vevb.com </th>
</p> </p> </p> </p> <th> conteúdo </th>
</p> </p> </p> </tr>
</p> </p> </p> <%
</p> </p> </p> </p> java.util.list list = feed.getentries ();
</p> </p> </p> </p> para (int i = 0; i <list.size (); i ++) {
</p> </p> </p> </p> com.sun.syndication.feed.synchrond.syndentry Entry = (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.getPublisedDate ()%> </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> </tabela>
</p> </div>
</p> <br>
</body>
</html>