ITeye博客

spring mvc 使用jquery 传json值给Controller时需要解决的问题

effort0829 · 2014-09-01 11:58 · springmvc · Web前端 · Spring · jQuery · MVC · Markdown

1 由于springmvc DispatcherServlet 使用“/”过滤了所有请求,那么静态资源也就被过滤掉了。页面加载jquery.js时404错误。 需要在springmvc 的配置文件中配置让js等静态资源可以找到 <mvc:resources mapping="/include//" location="/WEB-INF/include/" order="1"/> 其中 mapping="/include//"代表 请求路径contextPath/include下的所的请求,都在项目部署路径下"/WEB-INF/include"找.

如果出现下面的错误,可能是没有配置 <mvc:annotation-driven /> 的原因。 <mvc:annotation-driven /> 会自动注册DefaultAnnotationHandlerMapping与AnnotationMethodHandlerAdapter 两个bean,是spring MVC为@Controllers分发请求所必须的。 并提供了:数据绑定支持,@NumberFormatannotation支持,@DateTimeFormat支持,@Valid支持,读写XML的支持(JAXB),读写JSON的支持(Jackson)。 报错WARNING: No mapping found for HTTP request with URI

2 json支持 的两个 jar包 可以在http://mvnrepository.com/open-source/json-libraries找到

jackson-core-asl-1.9.13.jar   
http://central.maven.org/maven2/org/codehaus/jackson/jackson-core-asl/1.9.13/jackson-core-asl-1.9.13.jar

jackson-mapper-asl-1.9.13
http://central.maven.org/maven2/org/codehaus/jackson/jackson-mapper-asl/1.9.13/jackson-mapper-asl-1.9.13.jar

缺少ackson-core-asl-1.9.13.jar 时会报错 java.lang.NoClassDefFoundError: org/codehaus/jackson/JsonProcessingException

缺少jackson-mapper-asl-1.9.13 时会报错 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mappingJacksonHttpMessageConverter' defined in ServletContext resource : Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class : Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/codehaus/jackson/map/ObjectMapper

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。