728x90
1. μλλ‘μ΄λμ HttpURLConnection ν μ€νΈλ₯Ό μ§ννκΈ° μν΄ μΉ νλ‘μ νΈλ₯Ό μμ±νλ€.
(μλ κΈμ μ°Έκ³ ν΄μ μλ‘μ΄ νλ‘μ νΈλ₯Ό μμ±)
2. JSONObject, JSONArray, JSONParser ν΄λμ€λ₯Ό μ¬μ©νκΈ° μν΄ λ€μ λΌμ΄λΈλ¬λ¦¬λ₯Ό μΆκ°νλ€.
WebContent > WEB-INF > lib > json-simple-1.1.1.jar
3. μν μ½λ μμ± (test.jsp)
<%@ page language="java" contentType="application/json; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="java.util.stream.Collectors"%>
<%@ page import="org.json.simple.JSONObject"%>
<%@ page import="org.json.simple.JSONArray"%>
<%@page import="org.json.simple.parser.JSONParser"%>
<%
String sJsonObj = request.getReader().lines().collect(Collectors.joining(System.lineSeparator()));
JSONParser parser = new JSONParser();
System.out.println(sJsonObj);
Object obj = parser.parse(sJsonObj);
JSONObject jsonObj = (JSONObject)obj;
String input1 = (String) jsonObj.get("input1");
String input2 = (String) jsonObj.get("input2");
System.out.println(input1);
System.out.println(input2);
String retData = "Server to Client";
JSONObject jObject = new JSONObject();
try {
jObject.put("nRv", "0");
jObject.put("sRet", retData);
} catch(Exception e) {
jObject.put("nRv", "1");
e.printStackTrace();
}
out.println(jObject.toString());
%>
4. κ²°κ³Ό νλ©΄
λκΈ