ajax 통신

자바(Spring) 2020. 9. 6. 16:58
A라는 서비스에서 스크래핑해서

JSON 파일 저장후 

C라는 레포팅 서비스로 JSON파일 경로를 던저주는걸 개발중이다.

nodejs면 비동기로 때리면 끝나는데
스프링이니  ajax에 대한 결과를 alert이나 console.log밖에 안들어 온다

파일다 저장한 뒤에 페이지를 호출 해야된다.
 



JSP

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>

<meta charset="UTF-8">

<title>Insert title here</title>

</head>

<body>

newFile zzzzzzzzzzz




<form id="add-form" action="" method="post">

<input id="input-submit" type="submit" value="보내기" />


 </form>


<script>

$("#add-form").submit( function(event){

   

         $.ajax({

        type: "GET", 

        url:"/insert.do",

        dataType:"text", 

        success : function(result){

        alert(result);

        location.href = "http://localhost?result=" +result;   

        },

        error : function(a, b, c){

        alert(a + b + c);

        }

})

});

</script>



</body>

</html>



컨트롤러 


/*

 * Copyright 2008-2009 the original author or authors.

 *

 * Licensed under the Apache License, Version 2.0 (the "License");

 * you may not use this file except in compliance with the License.

 * You may obtain a copy of the License at

 *

 *      http://www.apache.org/licenses/LICENSE-2.0

 *

 * Unless required by applicable law or agreed to in writing, software

 * distributed under the License is distributed on an "AS IS" BASIS,

 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

 * See the License for the specific language governing permissions and

 * limitations under the License.

 */

package egovframework.example.sample.web;


import java.io.FileReader;

import java.util.HashMap;

import java.util.List;

import java.util.Map;


import egovframework.example.sample.service.EgovSampleService;

import egovframework.example.sample.service.LombokVO;

import egovframework.example.sample.service.SampleDefaultVO;

import egovframework.example.sample.service.SampleVO;


import egovframework.rte.fdl.property.EgovPropertyService;

import egovframework.rte.ptl.mvc.tags.ui.pagination.PaginationInfo;


import javax.annotation.Resource;


import org.springframework.stereotype.Controller;

import org.springframework.ui.Model;

import org.springframework.ui.ModelMap;

import org.springframework.validation.BindingResult;

import org.springframework.web.bind.annotation.ModelAttribute;

import org.springframework.web.bind.annotation.RequestBody;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestMethod;

import org.springframework.web.bind.annotation.RequestParam;

import org.springframework.web.bind.annotation.ResponseBody;

import org.springframework.web.bind.support.SessionStatus;

import org.springmodules.validation.commons.DefaultBeanValidator;

import org.json.simple.JSONArray;

import org.json.simple.JSONObject;

import org.json.simple.parser.JSONParser;

import org.json.simple.parser.ParseException;



@Controller

public class EgovSampleController {

@RequestMapping(value = "/jsonList.do")

public String jsonList(SampleVO sampleVO) throws Exception {


System.out.println("jsonList : " );

return "sample/NewFile";

}


@ResponseBody

@RequestMapping("/insert.do")

public String insert() {

System.out.println("insert");

return "aaaaaaaaaaaaaaaaaaaa";

}

}



바쁘니간 우선 돌아가게 만들어 놓고

나중에 코드 보수 좀 해야곘다.



'자바(Spring)' 카테고리의 다른 글

AsyncRestTemplate Spring boot 비동기  (0) 2021.02.09
JSON 파일 파싱 스프링 java VO저장  (0) 2020.08.29
블로그 이미지

iesay

,