The Debugging Chronicles : "코드의 미학"

[http-nio-8089-exec-1] WARN org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver -- Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content-Type 'application/x-www-form-urlencoded;charset=UTF-8' is not supporte 본문

오류 원인 분석 해결 방안

[http-nio-8089-exec-1] WARN org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver -- Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content-Type 'application/x-www-form-urlencoded;charset=UTF-8' is not supporte

sweetseonah1004 2024. 10. 14. 22:59

 

HttpMediaTypeNotSupportedException 오류는 클라이언트가 전송한 요청의 Content-Type이 서버에서 지원되지 않음을 나타냅니다. application/x-www-form-urlencoded는 주로 HTML 폼 데이터 전송에 사용됩니다. 이 오류를 해결하기 위해 몇 가지 방법을 통해 서버와 클라이언트 간의 미디어 타입 일치를 시도할 수 있습니다.

 

 

해결방법 

1.pom.xml 의존성 추가

	<dependency>
          <groupId>com.fasterxml.jackson.core</groupId>
          <artifactId>jackson-databind</artifactId>
      </dependency>

 

2.ds-servlet.xml bean추가

<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
      <property name="messageConverters">
         <list>
            <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
         </list>
      </property>
   </bean>

 

전체 코드

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:context="http://www.springframework.org/schema/context"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
                  http://www.springframework.org/schema/beans/spring-beans.xsd
                  http://www.springframework.org/schema/context
                  http://www.springframework.org/schema/context/spring-context-4.2.xsd">
   
   <context:component-scan base-package="com.koreait.app.view.board" />
   <context:component-scan base-package="com.koreait.app.view.member" />
      
   <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="viewResolver">
      <property name="prefix" value="./" />
      <property name="suffix" value=".jsp" />
   </bean>
   
   <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
       <property name="messageConverters">
           <list>
               <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
           </list>
       </property>
   </bean>
   
</beans>