Example of implementing RSS subscription Using JSP technology and jsprss subscription

Source: Internet
Author: User

Example of implementing RSS subscription Using JSP technology and jsprss subscription

RSS is also called aggregate RSS, which is a Simple way to share content online (also called aggregate content, Really Simple Syndication ). Generally, RSS subscriptions can be used to obtain information more quickly on highly time-sensitive content. The website provides RSS output, which is helpful for users to obtain the latest updates of website content. It is also the abbreviation of a specialized term in medicine, physics, mathematics, and other disciplines.

The original RSS was traced back to 1995 when ramanw.v. Guha and other senior technology groups at Apple Computer developed a content framework for testing. For more information about RSS, see here. Next we will generate RSS for our JSP website.

RSS purpose:

1. subscribe to a BLOG

(You can subscribe to the technical articles you need at work, or you can subscribe to the blogs of the authors who share your interests with you. In short, you can subscribe to the blogs you are interested in)

2. subscribe to news

(You can subscribe to whatever you want to know, whether it's strange things, celebrity news, or sports news.) you no longer need a website, a webpage, or a webpage to visit. As long as you subscribe the content you need to an RSS reader, the content will automatically appear in your reader, you do not need to refresh the webpage for an eager message, because once an update is made, the RSS reader will notify you by yourself.

The most basic RSS structure for implementing RSS functions using JSP technology:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>  <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"   xmlns:slash="http://purl.org/rss/1.0/modules/slash/">  </rss>  <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <rss version="2.0"  xmlns:dc="http://purl.org/dc/elements/1.1/"  xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/"  xmlns:wfw="http://wellformedweb.org/CommentAPI/"  xmlns:slash="http://purl.org/rss/1.0/modules/slash/"> </rss> 

Using JSP technology to implement RSS is actually an XML file!

Between <rss> </rss>, you can configure the RSS format you want to publish. For example, the RSS we want to publish this time is as follows:

<? Xml version = "1.0" encoding = "UTF-8" standalone = "yes"?> <Rss version = "2.0" xmlns: dc = "http://purl.org/dc/elements/1.1/" x mlns: trackback = "http://madskills.com/public/xml/rss/module/trackback/" xmlns: wfw = "http://wellformedweb.org/CommentAPI/" x mlns: slash = "http://purl.org/rss/1.0/modules/slash/"> <channel> <item> <title> JSP website RSS implementation </title> <author> neeke </author> <pubDate> </pubDate> <description> This is an RSS feed from Nick's technical blog </description> <category> J2EE technology </category> </item> </channel> </rss>

It is easy to understand its structure implementation. We create an IO stream, obtain the set of RSS resources to be published from the database, and write a row to an RSS. XML file according to its format and structure.

Public static void publishRss (String rssPath) {// get the RSS data set to be published ArrayList rssArticle = ArticleManager. getArticlesAll (); try {// create input/output stream FileWriter fw = new FileWriter (rssPath); BufferedWriter bw = new BufferedWriter (fw); // start to write data bw in the format. write ("<? Xml version = \ "1.0 \" encoding = \ "UTF-8 \" standalone = \ "yes \"?> \ R \ n "); bw. write (" <? Xml-stylesheet type = \ "text/xsl \" href = \ "CSS/rss. xslt \"?> "); Bw. write (" <rss version = \ "2.0 \" xmlns: dc = \" http://purl.org/dc/elements/1.1/ \ "Xmlns: trackback = \" http://madskills.com/public/xml/rss/module/trackback/ \ "Xmlns: wfw = \" http://wellformedweb.org/CommentAPI/ \ "Xmlns: slash = \" http://purl.org/rss/1.0/modules/slash/ \ "> \ R \ n"); bw. write ("<channel> \ r \ n"); for (int I = 0; I <rssArticle. size (); I ++) {ArticleBean article = (ArticleBean) rssArticle. get (I); bw. write ("<item> \ r \ n"); bw. write ("<title>" + article. getTitle () + "</title> \ r \ n"); bw. write ("<author>" + article. getAuthorId () + "</author> \ r \ n"); bw. write ("<pubDate>" + article. getPostTime () + "</pubDate> \ r \ n"); bw. write ("<description>" + article. getIntro () +" </Description> \ r \ n "); bw. write ("<category>" + article. getCateId () + "</category> \ r \ n"); bw. write ("</item> \ r \ n");} bw. write ("</channel> \ r \ n"); bw. write ("</rss>"); // close the stream. RSS has been published. Bw. close (); fw. close () ;}catch (IOException ex) {ex. printStackTrace ();}}

In this way, RSS is published using JSP. After my test is enabled, an error is prompted. Open the generated source file with notepad. However, our RSS file is completely unavailable, how is it possible? Then I opened the XML file using JBuilder and fainted ~ All Chinese characters are garbled and immediately realize where the problem is. Where? It is actually a file encoding problem! Convert the original bw. write ("<? Xml version = \ "1.0 \" encoding = \ "UTF-8 \" standalone = \ "yes \"?> \ R \ n "); The UTF-8 in the line of code to GBK, re-run the program, everything OK!

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.