简介:这是rss在web开发过程中的全方位应用。的详细页面,介绍了和java,.net,rss,csdn,sun,entry,有关的知识,加入收藏请按键盘ctrl+D,谢谢大家的观看!要查看更多有关信息,请点击此处
在web当中应用,要有以下两个开发包,
jdom.jar:jdom开源项目中(http://www.jdom.org/)
rome.jar : rome开源项目中(http://wiki.java.net/bin/view/javawsxml/rome)
关于rss在javaweb中的应用,分为两个步骤实施:
1.生成rss格式的xml文件:
public class feedwriter {
public static void main(string[] args) { boolean ok = false; if (args.length==2) { try { string feedtype = args[0]; string filename = args[1]; dateformat dateparser = new simpledateformat(date_format); syndfeed feed = new syndfeedimpl(); //feed流 feed.setfeedtype(feedtype); //设置rss版本 feed.settitle("sample feed (created with rome)"); //< title>设置标题 feed.setlink(http://www.csdn.net); //< link> feed.setdescription("this feed has been created using rome (java syndication utilities"); list entries = new arraylist(); syndentry entry; syndcontent description; entry = new syndentryimpl(); //子节点 entry.settitle("rome v1.0"); entry.setlink(http://www.csdn.net); entry.setpublisheddate(dateparser.parse("2004-06-08")); description = new syndcontentimpl(); description.settype("text/plain"); description.setvalue("initial release of rome"); entry.setdescription(description); entries.add(entry); entry = new syndentryimpl(); entry.settitle("rome v2.0"); entry.setlink(http://ww.csdn.net); entry.setpublisheddate(dateparser.parse("2004-06-16")); description = new syndcontentimpl(); //描述 description.settype("text/xml"); description.setvalue("bug fixes, < xml>xml< /xml> minor api changes and some new features"); entry.setdescription(description); entries.add(entry); entry = new syndentryimpl(); entry.settitle("rome v3.0"); entry.setlink("http://www.csdn.net"); entry.setpublisheddate(dateparser.parse("2004-07-27")); description = new syndcontentimpl(); description.settype("text/html"); description.setvalue("< p>more bug fixes, mor api changes, some new features and some unit testing< /p>"+ "< p>for details check the < a href=\"http://www.csdn.net\">changes log< /a>< /p>"); entry.setdescription(description); entries.add(entry); feed.setentries(entries); //设置子节点 writer writer = new filewriter(filename); syndfeedoutput output = new syndfeedoutput(); output.output(feed,writer); //写到文件中去 writer.close(); system.out.println("the feed has been written to the file ["+filename+"]"); ok = true; } catch (exception ex) { ex.printstacktrace(); system.out.println("error: "+ex.getmessage()); } } if (!ok) { system.out.println(); system.out.println("feedwriter creates a rss/atom feed and writes it to a file."); system.out.println("the first parameter must be the syndication format for the feed"); system.out.println(" (rss_0.90, rss_0.91, rss_0.92, rss_0.93, rss_0.94, rss_1.0 rss_2.0 or atom_0.3)"); system.out.println("the second parameter must be the file name for the feed"); system.out.println(); } } } |
< %@page contenttype="text/html"%> < %@page pageencoding="utf-8"%> < html> < head> < meta http-equiv="content-type" content="text/html; charset=utf-8"> < title>sina news< /title> < /head> < body> < % java.util.properties systemsettings = system.getproperties(); systemsettings.put("http.proxyhost", "mywebcache.com"); systemsettings.put("http.proxyport", "8080"); system.setproperties(systemsettings); string urlstr = "http://rss.sina.com.cn/news/marquee/ddt.xml"; java.net.urlconnection feedurl = new java.net.url(urlstr).openconnection(); feedurl.setrequestproperty("user-agent", "mozilla/4.0 (compatible; msie 5.0; windows nt; digext)"); com.sun.syndication.io.syndfeedinput input = new com.sun.syndication.io.syndfeedinput(); com.sun.syndication.feed.synd.syndfeed feed = input.build(new com.sun.syndication.io.xmlreader(feedurl)); %> < div align="center"> < h1>< %=feed.gettitle()%>< /h1> < table border=1 cellpadding=3 width="700"> < tr> < th>number< /th> < th>title< /th> < th>time< /th> < /tr> < % java.util.list list = feed.getentries(); for (int i=0; i< list.size(); i++) { com.sun.syndication.feed.synd.syndentry entry = (com.sun.syndication.feed.synd.syndentry)list.get(i); %> < tr> < td>< %=i+1%>< /td> < td>< a href="< %=entry.getlink()%>">< %=entry.gettitle()%>< /a>< /td> < td>< %=entry.getpublisheddate()%>< /td> < /tr> < %}%> < /table> < /div> < br> < /body> < /html> |