1. بحاجة إلى حزمتين: jdom.jar و rome.jar.
2. إنشاء مشروع ، ومحتوى web.xml كما يلي:
نسخة الكود كما يلي:
<؟
<إصدار Web-App = "2.5"
xmlns = "http://java.sun.com/xml/ns/javaee"
xmlns: xsi = "http://www.w3.org/2001/xmlschema-inostance"
XSI: schemalocation = "http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd ">
<قائمة الترحيب>
<lisp-file> index.jsp </elverfile>
</قائمة الترحيب>
</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 systemsTings = 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 ("عامل المستخدم" ،
</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 (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> <h> الرقم </th>
</p> </p> </p> </p> <th> العنوان </th>
</p> </p> </p> </p> <th> time www.vevb.com </h>
</p> </p> </p> </p> <th> المحتوى </th>
</p> </p> </p> </r>
</p> </p> </p> <٪
</p> </p> </p> </p> java.util.list list = feed.getentRies () ؛
</p> </p> </p> </p> لـ (int i = 0 ؛ i <list.size () ؛ i ++) {
</p> </p> </p> </p> com.sun.syndication.feed.synchrond.syndentry intern = (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 = "<٪ = intpl.getLink () ٪>"> <٪ = intpl.getTitle () ٪> </a> </td>
</p> </p> </p> </p> <td> <٪ = intrad.getPublishDate () ٪> </td>
</p> </p> </p> </p> <td> <٪ = intern.getDescription (). getValue () ٪> </td>
</p> </p> </p> </r>
</p> </p> </p> <٪
</p> </p> </p> </p>}
</p> </p> </p> ٪>
</p> </p> </table>
</p> </viv>
</p> <br>
</body>
</html>