1. ต้องการสองแพ็คเกจ: jdom.jar และ rome.jar
2. สร้างโครงการและเนื้อหาของ web.xml มีดังนี้:
การคัดลอกรหัสมีดังนี้:
<? xml version = "1.0" encoding = "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-file> index.jsp </welcome-file>
</ยินดีต้อนรับไฟล์-ลิสต์>
</eb-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 </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 = ใหม่ 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 อินพุต = ใหม่ 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> <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> สำหรับ (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.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>