ITeye博客

教你用Java生成RSS 简单实用

ariyue · 2010-09-10 00:40 · java · 编程语言 · 浏览器 · Java · XML · 生活 · Web · Markdown

    使用RSSLibJ异常简单,我们先设置好HttpServletResponse的Header,然后通过RSSLibJ输出XML即可:

Channel channel = new Channel(); channel.setDescription(account.getDescription()); baseUrl = baseUrl.substring(0, n); channel.setLink("http://server-name/home.c?accountId=" + accountId); channel.setTitle(account.getTitle()); List articles = facade.getArticles(accountId, account.getMaxPerPage(), 1); Iterator it = articles.iterator(); while(it.hasNext()) { Article article = (Article)it.next(); channel.addItem("http://server-name/article.c?articleId=" + article.getArticleId(), article.getSummary(), article.getTitle() ); } // 输出xml: response.setContentType("text/xml"); PrintWriter pw = response.getWriter(); pw.print(channel.getFeed("rss")); pw.close();

    rss用途很广泛,在快节奏的生活中,人们习惯快速的浏览对自己有用的信息,RSS订阅功能出现了,成功解决此问题,现在教会大家怎么用 java语言生成rss,很简单的方法,java无处不在

本文为leo博客独家发布,转载请保留原文地址http://www.dukai168.cn/blog/67.html, 否则将追究法律责任,谢谢配合.

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。