java开发中遇到过的一些错误

1. The type javax.servlet.ServletContext cannot be resolved. It is indirectly referenced from required .class files。

原因: 这是由于缺少了一个servlet-api.jar包所引起的。

解决方法:在安装的tomcat下的lib目录里面找到servlet-api.jar包,导入项目下的lib文件夹中即可。

或者:

项目名--> 右键 

Property--> 选择 

Java Build Path--> 选择 

Add External JARs--> 选择 

选择servlet-api.jar ,点击确定

2.在web项目中使用HttpServletRequest 的时候,报HttpServletRequest cannot be resolved to a type

同上

3. 在SpringMVC中报400错误,首先要考虑是否是参数绑定异常引起的。

4. SpringMVC上传文件遇到的错误

Request processing failed; nested exception is java.lang.IllegalArgumentException: Expected MultipartHttpServletRequest: is a MultipartResolver configured?

产生原因是,没有配置多媒体解析器multipartResolver

<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
   		<property name="defaultEncoding" value="utf-8"></property> 
   		<property name="maxUploadSize" value="10485760000"></property>
   		<property name="maxInMemorySize" value="40960"></property>
   </bean>

5. 在maven项目中,当引入多个xml配置文件的时候,用classpath可能会报错,这时候改为classpath*

<context-param>  
        <param-name>contextConfigLocation</param-name>  
        <param-value>classpath*:applicationContext*.xml</param-value>  
    </context-param> 

6. No converter found for return value of type: class java.util.ArrayList

在SpringMVC项目中,如果遇到这个错误,可能是由于项目中没有引入json包导致的

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

 如果还是没有解决,在springmvc配置文件中进行如下配置

<mvc:annotation-driven>
     <mvc:message-converters>
            <bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
            <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"/>
   </mvc:message-converters>
</mvc:annotation-driven>
发布了128 篇原创文章 · 获赞 6 · 访问量 3263

猜你喜欢

转载自blog.csdn.net/weixin_43318134/article/details/102539211