You can generate RSS feeds for your JSP-based web site easily. We'll show you how.

There are many Web sites that provide content useful for syndication and distribution to other sites, including Builder AU. Builder AU also has its own RSS feeds, which allow Web developers to incorporate content into their own sites.

Creating the RSS feed is one thing; delivering it for everyone to use is a different matter. In this article, we'll examine a solution that will help you deliver your RSS feed to other Web sites quickly and easily.

RSS refresher course
If you are already familiar with RSS, you may want to skip ahead. If not, keep reading to understand the particulars of what RSS is.

Put simply, RSS is an XML grammar for describing syndicated content. Content, of course, is a broad and ambiguous term. For our purposes, we'll define content as articles published on a news Web site. For example, Builder AU is a technology content resource. The site provides content in the form of articles, which can be syndicated and distributed to other sites. The RSS XML grammar describes the article headlines and descriptions and provides information about how to link back to the full content.

RSS XML documents consist of definitions. At the top level is the channel. Each content item, or article, in the RSS feed belongs to a channel. Often, an RSS feed will consist of a single channel containing all of the articles. The channel contains information such as the title and description, images of the content source, and a link back to the source. Listing A shows an example of the builderau.com.au RSS feed.

Listing A

The Java-Java two step
There are two components to serving up the feed to other Web sites. The immediate component answers the question of how to deliver the content to end users. The additional component answers the question of how to create what is delivered to the end users. The goal is to use a simple piece of JavaScript code to render a formatted feed directly to an end user. For example, within the HTML page, you should be able to place a single line such as the following:

<script src="http://www.example.com/serveFeed.jsp?hed=2&feed=1"></script>

In this case, the scriptlet points to a JSP page that will render the RSS headlines. So, the first Java component is the JavaScript that actually renders the feed in the user's page; the second is the JSP that creates the JavaScript based on an RSS document.

Working backwards
We'll start by examining the JavaScript output. Basically, our JSP will create an output that looks a lot like Listing B.

Listing B

This script uses the document object to write HTML out to the browser. In other words, the scriptlet above is essentially like an HTML client-side include that runs from the user's browser. When the browser sees the scriptlet tag, it calls the URL in the src and runs the output as JavaScript. The JavaScript, in this case, is the RSS headlines rendered as HTML.

Serving it up
An additional requirement for our feed was that it be parameter driven. There are three parameters that can be specified for this page:

Table A: Feed parameters

Parameter Description Valid Values Default Value
1 through 10 10
feed indicates which feed to display 1 or 2
desc indicates whether to display headline descriptions yes, no no

Do you need help with Java, C, or C++? Gain advice from Builder AU forums

Related links

Comments

1

Anthony Knape - 23/06/05

I am trying to find the download serverFeed.jsp so that I can complete the article by Brian Schaffner on RSS, JS and JSP.

Thank you.

anthony knape
214-680-6942

» Report offensive content

2

Anthony - 24/06/05

Anyone know where serveFeed.jsp is?
anthony@knape.com

» Report offensive content

3

Ella - 24/06/05

The serveFeed file is now available on the second page of this article as a zip file. Thanks!

» Report offensive content

4

Len - 06/07/07

Works well for straight XML feeds. When I try it with a WordPress feed, I get "unterminated string constant" errors.

» Report offensive content

5

David - 09/04/08

I have got it up and running but when pulling from a Polish RSS feed in UTF8 some characters are replaced by incorrect ones - any idea how to preserve the original encoding?

Here is a link http://media.breubezpieczenia.pl/getPR.po?tc=rss20&f=1319&enc=UTF

My Output:
Kurs Bezpiecznej Jazdy z Supermarketem Ubezpiecze? Samochodowych
BRE Ubezpieczenia wraz z mBankiem przygotowa?y dla Klientów SUS konkurs pod has?em "Bezpieczna Jazda z Supermarketem Ubezpiecze? Samochodowych". ...

Target Feed:
Kurs Bezpiecznej Jazdy z Supermarketem Ubezpieczeń Samochodowych
BRE Ubezpieczenia wraz z mBankiem przygotowały dla Klientów SUS konkurs pod hasłem "Bezpieczna Jazda z Supermarketem Ubezpieczeń Samochodowych". ...

» Report offensive content

6

David - 09/04/08

Hi! Managed to install this script which seems to be working fine apart from displaying international characters. My source feed is in UTF format and displays all characters correctly in a browser.
My html page invoking serveFeed.jsp is also set to UTF8

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

Some polish language characters seem to be converted though thereby no appearing correctly. Tried previewing directly via jsp and the same issue.

Any idea how to preserve them from the original feed?

» Report offensive content

7

Renuga - 07/05/08

In my application,i am displaying the XML files in the browser.

this is working for IE version 6 and Mozilla Firefox also.

But in IE 7 version,while displaying the XML file,it is showing an error like "Internet Explorer was unable to update this feed and will try again later.
".

Please help me to resolve this problem.

Any idea how to resolve this problem?

» Report offensive content

Leave a comment

You must read and type the 6 chars within 0..9 and A..F

* indicates mandatory fields.

7

Renuga - 05/07/08

In my application,i am displaying the XML files in the browser. this is working for IE version 6 and Mozilla Firefox also. But ... more

6

David - 04/09/08

Hi! Managed to install this script which seems to be working fine apart from displaying international characters. My source feed is ... more

5

David - 04/09/08

I have got it up and running but when pulling from a Polish RSS feed in UTF8 some characters are replaced ... more

Log in


Sign up | Forgot your password?

What's on?