1. JDOM.jarとRome.jarの2つのパッケージが必要です。
2。プロジェクトを作成すると、web.xmlのコンテンツは次のとおりです。
コードコピーは次のとおりです。
<?xmlバージョン= "1.0" encoding = "utf-8"?>
<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 ">
<Welcome-FileList>
<welcome-file> index.jsp </welcome-file>
</welcome-file-list>
</web-app>
3。次のようにindex.jspコンテンツを作成します。
コードコピーは次のとおりです。
次のようにコードをコピーします
<%@page contentType = "text/html"%>
<%@page pageencoding = "utf-8"%>
<html>
<head>
<meta http-equiv = "content-type" content = "text/html; charset = utf-8">
<title> sina news </title>
</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(互換; 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>番号</th>
</p> </p> </p> </p> <th>タイトル</th>
</p> </p> </p> </p> <th>時間www.vevb.com </th>
</p> </p> </p> </p> <th>コンテンツ</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.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>
</body>
</html>