zoukankan      html  css  js  c++  java
  • JAVA中RSS解析器(rome.jar和jdom.jar)范例

    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-list>
            <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>

        <%
            java.util.Properties systemSettings = System.getProperties();
            systemSettings.put("http.proxyHost", "mywebcache.com");
            systemSettings.put("http.proxyPort", "8080");
            System.setProperties(systemSettings);
            String urlStr = "http://rss.sina.com.cn/news/marquee/ddt.xml";
            java.net.URLConnection feedUrl = new java.net.URL(urlStr).openConnection();
            feedUrl.setRequestProperty("User-Agent",
                    "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
            com.sun.syndication.io.SyndFeedInput input = new com.sun.syndication.io.SyndFeedInput();
            com.sun.syndication.feed.synd.SyndFeed feed = input.build(new com.sun.syndication.io.XmlReader(feedUrl));
        %>

        <div align="center">
            <h1><%=feed.getTitle()%></h1>
            <table border=1 cellpadding=3 width="700">
                <tr>
                    <th>Number</th>
                    <th>Title</th>
                    <th>Time www.111cn.net</th>
                    <th>Content</th>
                </tr>

                <%
                    java.util.List list = feed.getEntries();
                    for (int i = 0; i < list.size(); i++) {
                        com.sun.syndication.feed.synd.SyndEntry entry = (com.sun.syndication.feed.synd.SyndEntry) list.get(i);
                    %>
                <tr>
                    <td><%=i + 1%></td>
                    <td><a href="<%=entry.getLink()%>"><%=entry.getTitle()%></a></td>
                    <td><%=entry.getPublishedDate()%></td>
                    <td><%=entry.getDescription().getValue() %></td>
                </tr>
                <%
                    }
                %>
            </table>
        </div>
        <br>
    </body>
    </html>
     


    4.完工。

    rss读取包工具:http://share.weiyun.com/72ac26b22b846505dcc1e14a623abd8d

    更多详细内容请查看:http://www.111cn.net/jsp/Java/58107.htm

  • 相关阅读:
    Mysql 服务无法启动 服务没有报告任何错误
    mysql国内镜像下载网址
    windows上自动设置java环境变量的脚本
    史上最详细的新浪广告系统技术架构优化历程
    十分钟理解广告系统
    Nginx基础配置指令
    nginx配置详情(总结)
    利用tcpdump抓包工具监控TCP连接的三次握手和断开连接的四次挥手
    Windows7配置QT-Android开发环境!
    一位计算机专业硕士毕业生的求职经历和感想[转载]
  • 原文地址:https://www.cnblogs.com/alibai/p/3572841.html
Copyright © 2011-2022 走看看