• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

Generating RSS from JSP

 
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Dave Brown
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Marshal
Posts: 67478
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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).
 
Bear Bibeault
Marshal
Posts: 67478
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Posts: 67478
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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



Concur.
 
Ulf Dittmer
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 301
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 don't get it. A whale wearing overalls? How does that even work? It's like a tiny ad wearing overalls.
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic