Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- window10
- Oracle
- Java
- WebtoB
- @Scheduled
- JEUS
- programmers
- Tomcat
- 개발자도구
- AES
- WINDOW11
- Login
- 브라우저
- 물리적주소
- 접근장치
- URLRewirte
- web server
- eGov
- FCM
- db
- 암호화
- TailMe
- dbms
- User-Agent
- scheduled
- Firebase
- mysql
- Was
- ua-parser
- 알고리즘
Archives
- Today
- Total
HD
네이버 Blog RSS data 사용 본문
반응형
<%@page import="java.net.HttpURLConnection"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.net.URL, org.jdom.Document, org.jdom.Element, org.jdom.input.SAXBuilder, org.xml.sax.InputSource, java.util.List, java.text.SimpleDateFormat, java.util.Date, java.util.Locale, java.text.ParseException "%>
<%@ page import="java.net.URLConnection, java.io.InputStream, java.io.InputStreamReader, java.io.BufferedReader, java.io.File" %>
<%
List blogList = null;
SimpleDateFormat oldFormat = new SimpleDateFormat("EEE, dd MMM yy", Locale.ENGLISH);
SimpleDateFormat oldFormat2 = new SimpleDateFormat("dd MMM yy", Locale.ENGLISH);
SimpleDateFormat newFormat = new SimpleDateFormat("yyyy-MM-dd");
Date parsedDate = null;
URL url = null;
String bLink = "";
String bTitle = "";
String bDescription = "";
String bPubDate = "";
int bSize = 6;
try { // 블로그
org.jdom.input.SAXBuilder parser = new org.jdom.input.SAXBuilder();
parser.setValidation(false);
parser.setIgnoringElementContentWhitespace(true);
url = new URL("해당 네이버 블로그 RSS URL");
org.xml.sax.InputSource is = new org.xml.sax.InputSource(url.openStream());
org.jdom.Document doc = parser.build(is);
org.jdom.Element root = doc.getRootElement();
org.jdom.Element channel = root.getChild("channel");
blogList = channel.getChildren("item");
}catch(Exception e){
e.printStackTrace();
}
%>
<!--naver-->
<li>
<ul>
<%
if(blogList != null) {
if(blogList.size() > bSize) {
bSize = 8;
} else {
bSize = blogList.size();
}
for(int i=0; i < bSize ; i++) {
org.jdom.Element el = (org.jdom.Element) blogList.get(i);
bLink = el.getChildText("link");
bTitle = el.getChildText("title");
bDescription = el.getChildText("description");
bPubDate = el.getChildText("pubDate");
try {
parsedDate = oldFormat.parse(bPubDate.substring(0,bPubDate.indexOf(":")-3));
} catch (ParseException e) {
e.printStackTrace();
}
bPubDate = newFormat.format(parsedDate);
%>
<li>
<a href="<%=bLink%>" title="새창 열기" target="_blank">
<div>
<p class="sns_content"><%=bDescription%></p>
<p class="sns_date"><%=bPubDate%></p>
</div>
<!--이미지가 따로 없어서 default 이미지-->
<img src="디폴트 이미지 경로" alt="이미지 alt">
</a>
</li>
<%
}
}
%>
</ul>
</li>
네이버 RSS URL로 가져온 xml 형식의 데이터를 가져와서 ul, li 태그에 마춰 데이터를 뿌려주는 작업
반응형
Comments