September 23, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Working with RSS and Oracle JDeveloper 10.1.3

  • August 1, 2005
  • By Chris Schalk
  • Send Email »
  • More Articles »

Using JSP Segments to Show Multiple RSS Feeds

These next steps show how to build a JSP page that will pull content from multiple RSS news feeds by using JSP Segments.

  1. To embed both the OTN and Developer.com News feeds onto a page, you can create two JSP Segments: developer.jspf & otn.jspf.
  2. To create the JSP segments, invoke the JSP Segment creation wizard in JDeveloper: File->New..->Web-Tier->JSP-> JSP Segment.
  3. After naming and generating empty JSP Segment files, copy and paste the respective code samples into the empty segment files. This code will pull the content from the different feeds. Also, notice that no taglib directives are needed for these pages; they are just segments.

    Important: Again, make sure to paste the code below into the source of the JSP Segment; otherwise, it will be translated to HTML markup.

    developer.jspf—For Developer.com

    <p><rss:channelTitle feedId="developer_news"/></p>
    <p><rss:channelImage feedId="developer_news" asLink="true"/></p>
    <p><rss:channelLink feedId="developer_news" asLink="true"/></p>
    <hr/>
    <rss:forEachItem feedId="developer_news">
       <li>
          <a href="<rss:itemLink feedId="developer_news"/>" >
             <rss:itemTitle feedId="developer_news"/>
          </a>
       <br/>
       <rss:itemDescription feedId="developer_news"/>
    </li>
    </rss:forEachItem>
    

    and the JSP segment for OTN:

    otn.jspf—For OTN

    <p><rss:channelTitle feedId="otn_news"/></p>
    <p><rss:channelImage feedId="otn_news" asLink="true"/></p>
    <p><rss:channelLink feedId="otn_news" asLink="true"/></p>
    <hr/>
    <rss:forEachItem feedId="otn_news">
       <li>
          <a href="<rss:itemLink feedId="otn_news"/>" >
             <rss:itemTitle feedId="otn_news"/>
          </a>
       <br/>
       <rss:itemDescription feedId="otn_news"/>
    </li>
    </rss:forEachItem>
    
  4. Next, create a master JSP page (that is not a JSP Segment) in a similar fashion to how you created your original JSP page. You can name the page "double.jsp".

  5. Once your JSP is created, drag and drop two RSS feed tags onto the page. These will allow you get content from both the OTN and Developer.com RSS feeds.

  6. Next, you can create an HTML table and drop two JSP Include directives onto the page that will point to the different OTN and developer jspf (segment) files that you created earlier.

    • To drop an HTML table, switch the Component Palette to "HTML Common" and drag and drop the Table component onto the JSP. Specify a table with 1 row, 2 columns, and 100% width.
    • To drop JSP Include Directives into the table cells, switch the palette to "JSP" and, because there are two "Include" on the palette, drop the second JSP Include, which is the Directive type of JSP Include. You can hover over the palette item to see which type of Include is which. The JSP include directive noted by the "@" symbol pulls the included content before the JSP is compiled.

    Here is the final code of a JSP page that shows both OTN and Developer.com's News Feeds:

    double.jsp

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <%@ page contentType="text/html;charset=windows-1252"%>
    <%@ taglib uri="http://sun.com/cnpi/rsstag" prefix="rss"%>
    <html>
       <head>
          <meta http-equiv="Content-Type"
                content="text/html;
                charset=windows-1252"></meta>
          <title>
             double
          </title>
          <link href="css/jdeveloper.css"
                rel="stylesheet"
                media="screen"></link>
       </head>
       <body>
          <h2>
             Fun with RSS
          </h2>
          <rss:feed feedId="otn_news"
                    url="http://www.oracle.com/technology/
                                syndication/rss_otn_news.xml"/>
          <rss:feed feedId="developer_news"
                    url="http://developer.com/icom_includes/
                                feeds/special/dev-5.xml"/>
    
           <table cellspacing="2"
                  cellpadding="3"
                  border="1"
                  width="100%">
              <tr>
                 <th>
                    Oracle Technology Network
                 </th>
                 <th>
                    Developer.com
                 </th>
              </tr>
              <tr>
                 <td>
                    <%@ include file="/otn.jspf"%>
                 </td>
                 <td>
                    <%@ include file="/developer.jspf"%>
                 </td>
              </tr>
          </table>
       </body>
    </html>
    
  7. At this point, you now can run the JSP page, double.jsp, by right-clicking and selecting Run. This will launch the page in JDeveloper's local embedded OC4J J2EE container (server). Your page should have the following appearance:


  8. Click here for a larger image.

  9. A final note: Everything shown here is with RSS version 2.0. The taglib can also work with older version of RSS, but the examples I've shown here are all 2.0.

  10. One more thing!! For your homework assignment: Create a news feed page for my Blog's RSS Feed!: http://www.jroller.com/rss/cschalk
  11. Note: You may not be able to view the RSS feed for my blog in your browser because it does not have a ".xml" extension, but the JSP feed tags should work regardless.

Summary

This article hopefully helped open the world of RSS to you by showing how easy it is to experiment with RSS using common J2EE technologies such as JSP and JSP tag libraries in a productive development environment such as JDeveloper. Good luck and have fun building your own custom RSS news fed pages using the JSP tag libraries highlighted here!

About the Author

Chris Schalk is a Principal Product Manager and Java Evangelist for Oracle's application server and development tools division. Chris' primary expertise is Web application development and he is responsible for defining the Web development experience for Oracle JDeveloper.

Chris has written numerous samples and articles for various publications, including Javapro and Oracle Magazine and is currently co-authoring JavaServer Faces—The Complete Reference through McGraw-Hill-Osborne. Chris also maintains a popular Blog on J2EE Web development at http://www.jroller.com/page/cschalk.





Page 3 of 3



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel