일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 톰캣
- oracle
- s4a
- 시작하기
- 코딩
- 오라클
- 잡토이 메이킹 코딩 학원
- 설정
- 유니티
- 스크래치
- html5
- Spring Security
- 아두이노
- 설치
- tomcat
- 예제
- 리브레캐드
- jobtoy
- MSSQL
- Android
- jsp
- librecad
- 안드로이드
- mysql
- 강좌
- 잡토이
- 운정
- Unity
- 파주
- 라즈베리파이
- Today
- Total
랩제이
[jsp] jsonp 테스트 본문
[jsp] jsonp 테스트
* 서버 JAVA 소스
@RequestMapping(value = "/main/jsonp", method = RequestMethod.GET)
@ResponseBody
public String jsonpTest(@RequestParam String id, @RequestParam String callback) {
Map<String, String> paramMap = new HashMap<String, String>();
paramMap.put("id", id);
paramMap.put("result", "success");
String result = null;
ObjectMapper mapper = new ObjectMapper();
try {
result = mapper.writeValueAsString(paramMap);
} catch (JsonGenerationException e) {
e.printStackTrace();
} catch (JsonMappingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(result);
return callback + "(" + result + ")";
}
* 클라이언트 JSP 소스
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
});
function getJsonTest1() {
$.getJSON("http://www.domain.com/webtest2/main/jsonp?id=user&callback=?",
function(data) {
alert(data.id + ", " + data.result);
}
);
}
function postJsonTest2() {
$.ajax({
type : "GET",
url : "http://www.domain.com/webtest2/main/jsonp",
data : "id=kyu",
dataType : "jsonp",
success : function(json) {
alert(json.id + ", " + json.result);
},
error : function(e) {
alert("error");
}
});
}
</script>
<a href="javascript:postJsonTest2();">
<a href="javascript:getJsonTest1();">test1</a> <br />
<a href="javascript:postJsonTest2();">test2</a> <br />
</a>
* 테스트 결과
[jsp] jsonp 테스트
'programming > jsp' 카테고리의 다른 글
[웹폰트] 본고딕 웹폰트 적용하기 (0) | 2018.01.22 |
---|---|
[jsp] jsp 파일 변경 (0) | 2017.09.25 |
[jsp] 업로드 버튼 file 숨기기 (0) | 2016.12.04 |
[jsp] to the cache because there was insufficient free space available after evicting expired cache entries - consider increasing the maximum size of the cache (0) | 2016.12.02 |
[jsp] P3P 쿠키 사용 설정하기 (0) | 2015.06.08 |