gnusraun

Egov @ResponseBody Ajax 설정 (404 Error 발생) 본문

Backend/Egov

Egov @ResponseBody Ajax 설정 (404 Error 발생)

gnusraun 2023. 5. 13. 15:05
728x90

초기 Egov 프레임워크를 이용하여 프로젝트를 생성하고 Ajax 통신할 경우 서버에서는 정상적으로 동작 하나

return page가 없어 404 Error가 발생

 

 

:: pom.xml

    jackson dependency 추가

 

<dependency>
     <groupid>com.fasterxml.jackson.core</groupid>
     <artifactid>jackson-core</artifactid>
     <version>2.8.8</version>
</dependency>
<dependency>
     <groupid>com.fasterxml.jackson.core</groupid>
     <artifactid>jackson-annotations</artifactid>
     <version>2.8.8</version>
</dependency>         
<dependency>
     <groupid>com.fasterxml.jackson.core</groupid>
     <artifactid>jackson-databind</artifactid>
     <version>2.8.8</version>
</dependency>

 

 

:: dispatcher-servlet.xml

    mvc:annotation-driven 추가

    ** 기존 egov프레임워크에서 사용하는 beans에서 xmlns:mvc , xsi:schemaLocation="*mvc*" (2개) 추가

          xmlns:mvc="http://www.springframework.org/schema/mvc"

          xsi:schemaLocation="http://www.springframework.org/schema/mvc

                                                        http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"

 

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:p="http://www.springframework.org/schema/p"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:mvc="http://www.springframework.org/schema/mvc"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
                http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
                http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">

<mvc:annotation-driven></mvc:annotation-driven>

...

 

 

:: Java

    @ResponseBody 사용

 

@RequestMapping(value = "/subAdd.do")
@ResponseBody
public Map<string, object> subAdd() throws Exception{
  Map map = new HashMap<string, object>();
  map.put("AA", "1");
  map.put("BB", "2");
  return map;
}

 

 

출처 - https://techislife.tistory.com/19

728x90