1. Jdom.jar와 Rome.jar의 두 가지 패키지가 필요합니다.
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 ">
<환영 파일리스트>
<환영 파일> index.jsp </welcome-file>
</환영 파일리스트>
</web-app>
3. 다음과 같이 index.jsp 컨텐츠를 만듭니다.
코드 사본은 다음과 같습니다.
코드를 다음과 같이 복사하십시오
<%@page contenttype = "text/html"%>
<%@page pageencoding = "utf-8"%>
<html>
<헤드>
<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> 문자열 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> <테이블 테두리 = 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 = "<%= enlic.getLink ()%>"> <%= entertitle ()%> </a> </td>
</p> </p> </p> </p> <td> <%= entry.getPublishedDate ()%> </td>
</p> </p> </p> </p> <td> < %= enterd.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>