-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
408 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package com.sai.servlet; | ||
|
||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.annotation.WebServlet; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import javax.servlet.http.HttpSession; | ||
import javax.swing.plaf.synth.SynthSeparatorUI; | ||
|
||
import org.json.simple.JSONObject; | ||
|
||
import com.sai.dao.MemberDAO; | ||
import com.sai.vo.MemberVO; | ||
|
||
public class LoadFriendsToMap implements Action { | ||
|
||
@Override | ||
public String execute(HttpSession session, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | ||
response.setContentType("text/html;charset=UTF-8"); | ||
|
||
System.out.println("서블릿 테스트"); | ||
|
||
String sessId = (String) session.getAttribute("sessId"); | ||
System.out.println(sessId); | ||
|
||
String[] friendsId = null; | ||
|
||
//알고리즘에 참여한 memberI d값들을 담는 JSONObject | ||
JSONObject friendsInfo = new JSONObject(); | ||
//알고리즘에 참여한 member들의 지하철역의 이름을 담은 JSONObject | ||
JSONObject stationList = new JSONObject(); | ||
|
||
JSONObject result = new JSONObject(); | ||
//loadFriendsMap()을 통해서 friendsId배열에 친구들 ID값들 담음 | ||
friendsId = new MemberDAO().loadFriendsMap(sessId); | ||
|
||
//searchFriendInfo()를 통해서 알고리즘에 참여한 멤버의 memberId, memberName, memberStation을 fInfo에 삽입 | ||
for(int i = 0; i < friendsId.length; i++) { | ||
JSONObject fInfo = new MemberDAO().searchFriendInfo(friendsId[i]); | ||
//검색한 모든 친구들의 데이터(memberId, memberName, memberStation)를 friendsInfo에 넣음. | ||
//friendsInfo.put(i, fInfo); | ||
|
||
//System.out.println(friendsInfo); | ||
|
||
//friendsId JSONObject에서 객체를 하나씩 꺼내 그 안의 memberStation 정보를 꺼내옴 | ||
//for(int j = 0; j < friendsId.length; j++) { | ||
String fStation = (String) fInfo.get("memberStation"); | ||
|
||
//꺼내온 지하철역명으로 해당 역의 x, y 좌표를 얻어옴. | ||
JSONObject station = new MemberDAO().searchLocation(fStation); | ||
System.out.println("station 값은 " + station); | ||
|
||
//stationList에 각각의 역 좌표를 삽입함. | ||
//stationList.put(fStation, station); | ||
|
||
//System.out.println(stationList.get("덕정")); | ||
|
||
String data1 = (String) fInfo.get("memberId"); | ||
String data2 = (String) fInfo.get("memberName"); | ||
String data3 = (String) fInfo.get("memberStation"); | ||
String data4 = (String) station.get("wgsX"); | ||
String data5 = (String) station.get("wgsY"); | ||
|
||
JSONObject total = new JSONObject(); | ||
|
||
total.put("memberId", data1); | ||
total.put("memberName", data2); | ||
total.put("memberStation", data3); | ||
total.put("wgsX", data4); | ||
total.put("wgsY", data5); | ||
|
||
result.put(i, total); | ||
|
||
System.out.println("단계 데이터" + result.get(i)); | ||
//} | ||
} | ||
|
||
|
||
|
||
/*for(int i = 0; i < friendsId.length; i++) { | ||
JSONObject fData = (JSONObject) friendsInfo.get(i); | ||
JSONObject sData = (JSONObject) stationList.get(i); | ||
result | ||
}*/ | ||
|
||
System.out.println("최종 데이터" + result); | ||
|
||
PrintWriter out = response.getWriter(); | ||
out.println(result); | ||
|
||
return null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.sai.servlet; | ||
|
||
import java.sql.Connection; | ||
import java.sql.DriverManager; | ||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
|
||
import org.json.simple.JSONObject; | ||
|
||
public class MakePathToJson { | ||
static float mapX; | ||
static float mapY; | ||
|
||
public static JSONObject makeJson(String str) throws Exception { | ||
String shtState = str; | ||
String sub[]; | ||
sub = shtState.split(","); | ||
|
||
JSONObject result = new JSONObject(); | ||
|
||
PreparedStatement pstmt = null; | ||
ResultSet rs = null; | ||
|
||
try { | ||
Class.forName("com.mysql.jdbc.Driver"); | ||
System.out.println("드라이버 검색 OK"); | ||
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3307/hanium_prac", "root", "qkqh3635^^"); | ||
System.out.println("접속 성공"); | ||
|
||
for(int i = 0; i < sub.length; i++) { | ||
JSONObject res = new JSONObject(); | ||
|
||
String sql = "select stationName, subwayName, wgsX, wgsY from subway where stationId = ?"; | ||
|
||
pstmt = conn.prepareStatement(sql); | ||
|
||
pstmt.setInt(1, Integer.parseInt(sub[i])); | ||
|
||
rs = pstmt.executeQuery(); | ||
while(rs.next()) { | ||
String stationName = rs.getString(1); | ||
String subwayName = rs.getString(2); | ||
float wgsX = rs.getFloat(3); | ||
float wgsY = rs.getFloat(4); | ||
|
||
mapX = wgsX; | ||
mapY = wgsY; | ||
|
||
res.put("stationName", stationName); | ||
res.put("subwayName", subwayName); | ||
res.put("wgsX", wgsX); | ||
res.put("wgsY", wgsY); | ||
|
||
result.put(i, res); | ||
|
||
} | ||
|
||
} | ||
|
||
pstmt.close(); | ||
|
||
} catch (Exception e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.sai.servlet; | ||
|
||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.annotation.WebServlet; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import javax.servlet.http.HttpSession; | ||
|
||
import org.json.simple.JSONObject; | ||
|
||
import com.sai.dao.MemberDAO; | ||
import com.sai.vo.MemberVO; | ||
|
||
/** | ||
* Servlet implementation class ModifyIMyInfo | ||
*/ | ||
public class ModifyMyInfo implements Action { | ||
|
||
@Override | ||
public String execute(HttpSession session, HttpServletRequest request, HttpServletResponse response) | ||
throws ServletException, IOException { | ||
response.setContentType("text/html;charset=UTF-8"); | ||
String memberId = (String) session.getAttribute("sessId"); | ||
String memberPw = request.getParameter("memberPw"); | ||
String memberName = request.getParameter("memberName"); | ||
String memberPhone = request.getParameter("memberPhone"); | ||
String memberStation = request.getParameter("memberStation"); | ||
|
||
System.out.println("----->" + memberId + "------>" + memberPw); | ||
|
||
new MemberDAO().modifyInfo(memberId, memberPw, memberName, memberPhone, memberStation); | ||
|
||
JSONObject json = new MemberDAO().showMyInfo(memberId); | ||
|
||
memberId = (String) json.get("memberId"); | ||
memberPw = (String) json.get("memberPw"); | ||
memberName = (String) json.get("memberName"); | ||
memberPhone = (String) json.get("sessPhone"); | ||
memberStation = (String) json.get("sessStation"); | ||
|
||
session.setAttribute("sessId", memberId); | ||
session.setAttribute("sessPw", memberPw); | ||
session.setAttribute("sessName", memberName); | ||
session.setAttribute("sessPhone", memberPhone); | ||
session.setAttribute("sessStation", memberStation); | ||
|
||
System.out.println("새로 설정된 세션에 저장된 이름: " + session.getAttribute("sessName")); | ||
|
||
JSONObject result = new JSONObject(); | ||
|
||
result.put("sessId", memberId); | ||
result.put("sessPw", memberPw); | ||
result.put("sessName", memberName); | ||
result.put("sessPhone", memberPhone); | ||
result.put("sessStation", memberStation); | ||
|
||
PrintWriter out = response.getWriter(); | ||
out.println(result); | ||
//request.setAttribute("myInfo", vo); | ||
|
||
response.setContentType("text/html;charset=UTF-8"); | ||
|
||
return "myPage.html"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package com.sai.servlet; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.io.PrintWriter; | ||
import java.net.HttpURLConnection; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
|
||
import javax.servlet.ServletException; | ||
import javax.servlet.annotation.WebServlet; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
import javax.servlet.http.HttpSession; | ||
|
||
import org.json.simple.JSONArray; | ||
import org.json.simple.JSONObject; | ||
import org.json.simple.parser.JSONParser; | ||
|
||
/** | ||
* Servlet implementation class ShowHotPlace | ||
*/ | ||
public class ShowHotPlace implements Action { | ||
|
||
@Override | ||
public String execute(HttpSession session, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | ||
response.setContentType("text/html;charset=UTF-8"); | ||
|
||
System.out.println("--------------"); | ||
|
||
JSONObject result = new JSONObject(); | ||
|
||
String addr = "http://api.visitkorea.or.kr/openapi/service/rest/KorService/areaBasedList?ServiceKey="; | ||
|
||
String serviceKey = "LzJ73NnpJ9i8FwimSqcbaJpLp6x9nN4TCDnDBSPhf8TEA05I5fi6G%2FIhjRdbQcD5FZ%2FH778Vpm4vE%2F9OTB6D6Q%3D%3D"; | ||
String param = ""; | ||
param = param + "&" + "areaCode=1"; | ||
param = param + "&" + "MobileOS=ETC&MobileApp=SAI"; | ||
param = param + "&" + "arrange=B"; | ||
param = param + "&" + "numOfRows=50"; | ||
param = param + "&" + "_type=json"; | ||
addr = addr + serviceKey + param; | ||
|
||
URL url; | ||
|
||
try { | ||
url = new URL(addr); | ||
|
||
HttpURLConnection conn; | ||
String protocol = "GET"; | ||
BufferedReader buffer; | ||
String json; | ||
|
||
conn = (HttpURLConnection)url.openConnection(); | ||
conn.setRequestMethod(protocol); | ||
buffer = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8")); | ||
|
||
json = buffer.readLine(); | ||
|
||
try { | ||
JSONParser jsonParser = new JSONParser(); | ||
|
||
JSONObject jsonObject = (JSONObject) jsonParser.parse(json); | ||
JSONObject responseObject = (JSONObject) jsonObject.get("response"); | ||
JSONObject bodyObject = (JSONObject) responseObject.get("body"); | ||
JSONObject itemsObject = (JSONObject) bodyObject.get("items"); | ||
JSONArray itemList = (JSONArray) itemsObject.get("item"); | ||
|
||
System.out.println("itemList은 " + itemList.size() + "개입니다."); | ||
|
||
for(int i = 0; i < itemList.size(); i++) { | ||
JSONObject res = new JSONObject(); | ||
|
||
JSONObject list = (JSONObject) itemList.get(i); | ||
String firstImage = (String) list.get("firstimage"); | ||
String title = (String) list.get("title"); | ||
String readCount = list.get("readcount").toString(); | ||
String addr1 = (String) list.get("addr1"); | ||
String addr2 = (String) list.get("addr2"); | ||
String tel = (String) list.get("tel"); | ||
String areacode = list.get("areacode").toString(); | ||
String contentId = list.get("contentid").toString(); | ||
String contentTypeId = list.get("contenttypeid").toString(); | ||
Double mapX = Double.parseDouble(list.get("mapx").toString()); | ||
Double mapY = Double.parseDouble(list.get("mapy").toString()); | ||
|
||
res.put("firstImage", firstImage); | ||
res.put("title", title); | ||
res.put("readCount", readCount); | ||
res.put("addr1", addr1); | ||
res.put("addr2", addr2); | ||
res.put("tel", tel); | ||
res.put("areaCode", areacode); | ||
res.put("contentId", contentId); | ||
res.put("contentTypeId", contentTypeId); | ||
res.put("mapX", mapX); | ||
res.put("mapY", mapY); | ||
|
||
result.put(i, res); | ||
|
||
} | ||
|
||
PrintWriter out = response.getWriter(); | ||
out.println(result); | ||
//request.setAttribute("hotPlaceList", result); | ||
|
||
} catch (Exception e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
|
||
} catch (MalformedURLException e1) { | ||
// TODO Auto-generated catch block | ||
e1.printStackTrace(); | ||
} | ||
|
||
return null; | ||
|
||
} | ||
|
||
} | ||
|
||
|
||
|
Oops, something went wrong.