본문 바로가기

Dev./Back-end

JSP로 RSS구현하기 예제

<?xml version="1.0" encoding="EUC-KR"?>
<%@ page contentType="text/xml;charset=euc-kr"%>
<%@ page import="java.util.*, java.text.*" %>
<%@ page import="" %>

<%
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.US);
String serverPath = "http://" + request.getServerName();
if (request.getServerPort() != 80) {
serverPath += ":" + request.getServerPort();
}
serverPath += request.getContextPath();

List<History> list = HistoryDao.getHistorys(2);
%>
<rss version="2.0">
<channel>
<title> 문서목록</title>
<link><%=serverPath%>/hist_lst.jsp</link>
<description>문서목록을 보실 수 있습니다.</description>
<language>ko</language>
<pubDate><%=sdf.format(cal.getTime())%></pubDate>
<lastBuildDate><%=sdf.format(cal.getTime())%></lastBuildDate>
<docs><%=serverPath%>/hist_rss.jsp</docs>
<webMaster>master@history.or.kr</webMaster>
<%
for (History b : list) {
%>
<item>
<title><%=b.getTitle()%></title>
<link><%=serverPath%>/hist_viw.jsp?histId=<%=b.getDataId()%></link>
<description>
<![CDATA[

[내용]<br />
<%=b.getContent()%>
]]>
</description>
<pubDate><%=b.getRegDate()%></pubDate>
<guid><%=serverPath%>/hist_viw.jsp?dataId=<%=b.getDataId()%></guid>
</item>
<%
}
%>
</channel>
</rss>