1. Necesito dos paquetes: Jdom.jar y Rome.jar.
2. Cree un proyecto, y el contenido de Web.xml es el siguiente:
La copia del código es la siguiente:
<? xml versión = "1.0" encoding = "utf-8"?>
<Web-app versión = "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 ">
<Bienvenido-File-List>
<velceed-file> index.jsp </Welcome-File>
</Welcome-File-List>
</web-app>
3. Cree un contenido index.jsp de la siguiente manera:
La copia del código es la siguiente:
Copie el código de la siguiente manera
<%@página contentType = "text/html"%>
<%@página PageEncoding = "UTF-8"%>
<html>
<Evista>
<meta http-equiv = "content-type" content = "text/html; charset = utf-8">
<title> Sina News </title>
</ablo>
<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 (Systemyettings);
</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 (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> número </th>
</p> </p> </p> </p> <th> title </th>
</p> </p> </p> </p> <th> time www.vevb.com </th>
</p> </p> </p> </p> <th> contenido </th>
</p> </p> </p> </tr>
</p> </p> </p> <%
</p> </p> </p> </p> java.util.list list = feed.getEntries ();
</p> </p> </p> </p> for (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> </table>
</p> </div>
</p> <br>
</body>
</html>