JSP technology to implement the RSS Subscription function Example _jsp programming

Source: Internet
Author: User

RSS is also called aggregate RSS is an easy way to share content online (also called aggregation content, really Simple Syndication). RSS feeds are often used on time-sensitive content to get information more quickly, and Web sites provide RSS output to help users get the latest updates on the content of their sites. It is also the abbreviation for the English abbreviations of the proper nouns in medicine, physics, mathematics and other subjects.

The initial RSS goes back to 1995, when Ramanathan v. Guha and other advanced technology groups in Apple developed a content framework for testing. For more information about RSS to see here, let's generate RSS for our JSP site.

RSS usage:

1, Subscribe to Blog

(You can subscribe to the technical articles you need in your work, or subscribe to the blog of the author you have a common interest in, in short, you are interested in what you can order)

2, subscribe to the News

(whether it's anecdotes, star News, sports, as long as you want to know, you can subscribe) you don't need a website, a Web page to go shopping. As long as it subscribes to the content you need in an RSS reader, the content will automatically appear in your reader, and you don't have to refresh the page for a message you're eager to know, because once you have the update, the RSS reader will notify you.

Using JSP technology to achieve the most basic RSS function RSS structure:

<?xml version= "1.0" encoding= "UTF-8" standalone= "yes"?> <rss "version=" "2.0" xmlns:dc=  
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 the RSS function is actually an XML file!

Between <rss></rss> we are free to configure the format of the RSS we want to publish. For example, the RSS we are going to publish is like this:

<?xml version= "1.0" encoding= "UTF-8" standalone= "yes"?> <rss "version=" "2.0" xmlns:dc=  
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>2008-10-04</pubDate>  
<description> This is the rss</description> from Nick Tech Blog Blog  
<category>j2ee Technology </category>  
</item>  
</channel>  
</rss> 

Understanding its structure is easy to achieve. We create the IO stream and get a collection of the RSS resources we want to publish from the database, and then write to a rss.xml file in its format and in one line of the structure.

public static void Publishrss (String rsspath) {//Get the collection of RSS data to be published ArrayList rssarticle = Articlemanager.getar  
    Ticlesall ();  
      try {//create input output stream FileWriter FW = new FileWriter (Rsspath); BufferedWriter bw = new BufferedWriter (FW);  
      Start writing data in the format bw.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 and RSS is released.  
      Bw.close ();  
    Fw.close ();  
    catch (IOException ex) {ex.printstacktrace (); 
 }  
  }

In this way with JSP to achieve the release of RSS, after my test opened will be prompted error, with Notepad to open the generated source files, but our RSS file is a little problem is not wow, how possible? Then with JBuilder Open this XML file, faint ~ Chinese characters are all garbled, immediately realize the problem is where. Where is it? is actually the file coding problem! Replace the original Bw.write ("<?xml version=\" 1.0\ "encoding=\" utf-8\ "standalone=\" yes\ ">\r\n") with the UTF-8 in the line code, and rerun the program, Everything ok!

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.