I'm using springframework and have question about it!
$.ajax({
type: "POST",
url: "/updateCell.do",
data: JSON.stringify(data),
contentType: "application/json; charset=UTF-8",
success: function(response) {
sweetAlert('success','It has been successfully edited.','');
},
error: function(xhr, status, error) {
sweetAlert('error','A problem has been detected.','');
}
});
when I tried this ajax, which has 'application/json' content type
org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'application/json;charset=UTF-8' not supported
This error got happended... so I add
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
</list>
</property>
this to 'dispatcher-servlet.xml' and it worked!
and then I tried to send ajax, which has 'text/xml' content type
var wfsTransactionRequest =
'<wfs:Transaction ' +
'xmlns:wfs="http://www.opengis.net/wfs" ' +
'xmlns:gml="http://www.opengis.net/gml" ' +
'xmlns:ogc="http://www.opengis.net/ogc" ' +
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
'xmlns:feature="http://vndan" ' +
'service="WFS" version="1.2.0" ' +
'xsi:schemaLocation="http://www.opengis.net/wfs ' +
'http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd">' +
'<wfs:Update typeName="vndan:' + tableName + '">' +
'<wfs:Property>' +
'<wfs:Name>geom</wfs:Name>' +
'<wfs:Value>' + geomXML + '</wfs:Value>' +
'</wfs:Property>' +
'<ogc:Filter>' +
'<ogc:FeatureId fid="' + fid + '"/>' +
'</ogc:Filter>' +
'</wfs:Update>' +
'</wfs:Transaction>';
$.ajax({
url: '/gis/wfs',
type: 'POST',
dataType: 'xml',
data: wfsTransactionRequest,
contentType: 'text/xml',
success: function (data) {
toastr.success('It has been successfully edited.');
},
error: function (xhr, status, error) {
console.error(error);
}
});
like this...
but in this case, Content type 'text/xml' not supported error happened.
so I added
<bean class="org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter" />
this to 'dispatcher-servlet.xml', but nothing changed.
when I deleted
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
</list>
</property>
this from 'dispatcher-servlet.xml', I could send ajax, which has text/xml content type, but couldn't send ajax, which has 'application/json' content type.
These codes worked well in another project, so I don't think it's a problem related to Server or other things...
To sum up, I can only send one of the two contents type. Is there anyway that I could send both ajax?
Here is my 'dispatcher-servlet.xml' :)
<?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: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">
<context:component-scan base-package="egovframework">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service"/>
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
</context:component-scan>
<context:component-scan base-package="vndan">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service"/>
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
</context:component-scan>
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
<property name="webBindingInitializer">
<bean class="egovframework.example.cmmn.web.EgovBindingInitializer"/>
</property>
<property name="messageConverters">
<list>
<bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
<bean class="org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter" />
</list>
</property>
</bean>
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping">
<property name="interceptors">
<list>
<ref bean="localeChangeInterceptor" />
</list>
</property>
</bean>
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver" />
<bean id="localeChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="language" />
</bean>
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="defaultErrorView" value="cmmn/egovError"/>
<property name="exceptionMappings">
<props>
<prop key="org.springframework.dao.DataAccessException">cmmn/dataAccessFailure</prop>
<prop key="org.springframework.transaction.TransactionException">cmmn/transactionFailure</prop>
<prop key="egovframework.rte.fdl.cmmn.exception.EgovBizException">cmmn/egovError</prop>
<prop key="org.springframework.security.AccessDeniedException">cmmn/egovError</prop>
</props>
</property>
</bean>
<bean class="org.springframework.web.servlet.view.UrlBasedViewResolver" p:order="1"
p:viewClass="org.springframework.web.servlet.view.JstlView"
p:prefix="/WEB-INF/jsp/vndan/" p:suffix=".jsp"/>
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver" id="viewResolver" p:order="0" />
<bean class="org.springframework.web.servlet.view.json.MappingJackson2JsonView" id="jsonView">
<property name="contentType" value="application/json;charset=UTF-8"/>
</bean>
<!-- For Pagination Tag -->
<bean id="imageRenderer" class="egovframework.example.cmmn.web.EgovImgPaginationRenderer"/>
<bean id="paginationManager" class="egovframework.rte.ptl.mvc.tags.ui.pagination.DefaultPaginationManager">
<property name="rendererType">
<map>
<entry key="image" value-ref="imageRenderer"/>
</map>
</property>
</bean>
<!-- /For Pagination Tag -->
<mvc:view-controller path="/cmmn/validator.do" view-name="cmmn/validator"/>
<mvc:default-servlet-handler />
<mvc:annotation-driven />
</beans>