File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Generating RSS from JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Generating RSS from JSP" Watch "Generating RSS from JSP" New topic
Author

Generating RSS from JSP

Dave Brown
Ranch Hand

Joined: Mar 08, 2005
Posts: 301
Anyone know of any samples/tutorials showing how to output an RSS using jsp/jstl.

I have quite a simple scenario where I want to keep people updated of the latest items within a specific db table. Rather than have a running task that sounds out emails every so often, It's seems a much simpler idea to let them subscribe to an RSS feed.

Thanks


Regards, Dave Brown
SCJP 6 - [url]http://www.dbws.net/[/url] - Check out Grails Forum
Maryam Nouhnejad
Ranch Hand

Joined: Oct 04, 2006
Posts: 39
Dear Dave,
I haven't learn RSS myself but may be this link can help you. I've used some tutorials of this site before and they were good.

http://www.w3schools.com/rss/default.asp

Hope it helps you,
Maryam
Dave Brown
Ranch Hand

Joined: Mar 08, 2005
Posts: 301
Hi, thanks for that. Although I understand the fundamentals behind RSS, my problem is the delivery. If I create a new JSP and simply add some xml to it adhering to the RSS protocol, then call the page. Nothing happens. And if I try and subscribe to it from a reader such as thunderbird, it says the feed is invalid.

heres the content of my jsp..



Not sure why it doesnt like to play...
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
You are neglecting the way JSp works - it literally outputs text so:

puts out a crlf before the <?xml
That is not legal in an xml document, the < must be the first character.
Remove all that formatting and try again.

Bill
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41499
    
  53
Instead of using JSP, you may want to put a servlet in front of it, so that you can do this.

It'll save you a lot of bandwith, and -since you're generating feeds on the fly- a lot of processing.


Ping & DNS - my free Android networking tools app
Dave Brown
Ranch Hand

Joined: Mar 08, 2005
Posts: 301
Do you mean use a servlet instead of a jsp - or as well as ?

Is the problem of using a jsp simply down to whitespace between tags ?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60992
    
  65

JSP preserves all template text in the output, including whitespace and CRLFs. When outputting content that is whitespace-sensitive, you need to take care with the JSP formatting as Ulf pointed out. You may find this article enlightening.

You could either emit the content from a servlet, or write your JSP very very carefully and examine its output to ensure that it follows all the XML/RSS formatting rules.
[ June 13, 2007: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Bear Bibeault:
JSP preserves all template text in the output, including whitespace and CRLFs. When outputting content that is whitespace-sensitive, you need to take care with the JSP formatting as Ulf pointed out. You may find this article enlightening.

You could either emit the content from a servlet, or write your JSP very very carefully and examine its output to ensure that it follows all the XML/RSS formatting rules.

[ June 13, 2007: Message edited by: Bear Bibeault ]


You will also want to test your JSPs in any containers that you intend to support as the exact rules, regarding whitespace, are not dictated by the JSP spec and can vary from container to container (and version to version of any given container).


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60992
    
  65

Good point, Ben. Some containers may also have options for removing whitespace before sending the response on its way, and of course, you could always write a filter to do so yourself.
Dave Brown
Ranch Hand

Joined: Mar 08, 2005
Posts: 301
Darn it, there was me thinking a jsp rss feed would be a 5 minute task. Since I can use the sql & forEach tags, it would have been ideal.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

JSTL SQL tags are a cancer within the whole JSTL concept.
They blatantly violate all the principals of scriptless JSP architecture that the JSTL was created to encourage.

There is even a blurb within the JSTL spec that warns against using them in anything but prototypes and trivial applications.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60992
    
  65

Originally posted by Ben Souther:
JSTL SQL tags are a cancer within the whole JSTL concept.


Concur.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41499
    
  53
Originally posted by Dave Brown:
Darn it, there was me thinking a jsp rss feed would be a 5 minute task. Since I can use the sql & forEach tags, it would have been ideal.


Not sure what kind of traffic you're expecting, but when we did precisely that here on JavaRanch (JSP page re-generating the feed for each access), it brought the server to its knees. That's why we switched to pre-fabricated feeds (essentially static files) that are updated when necessary.
Dave Brown
Ranch Hand

Joined: Mar 08, 2005
Posts: 301
It will be very limited, 2-3 people would use the feed.

Maybe I'll just stick with an email alert.

Thanks for the input anyway fellas.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Generating RSS from JSP