`
effort0829
  • 浏览: 851 次
  • 性别: Icon_minigender_1
  • 来自: 西安
最近访客 更多访客>>
社区版块
存档分类
最新评论

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

阅读更多
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 [/WEB-INF/classes/spring/servlet1.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.http.converter.json.MappingJacksonHttpMessageConverter]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/codehaus/jackson/map/ObjectMapper
  • mvc.zip (6.4 MB)
  • 下载次数: 153
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics