setCharacterEncoding is undefined

setCharacterEncoding is undefined  

When working on a project, after downloading a project from svn to myEclipse , the project reports an error and opens the wrong java file, prompting the following error:

Servlet.service() for servlet jsp threw exception   java.lang.Error: Unresolved compilation problem: The method setCharacterEncoding(String) is undefined for the type ServletResponse

Simply put, the setCharacterEncoding method is undefined.

 

Solution 1

Open the buildpath and find that both servlet.jar and javaEE 5 are imported . All of them have javax.servlet.http.HttpServletRequest , and the default in the project is the class in the imported servlet.jar  , and the jar version may be too low, anyway , there is no setCharacterEncoding method in the HttpServletRequest class of the jar package . Just remove servlet.jar .

This method failed.

Solution 2

This method is a method in the interface ServletResponse , but there is no such method in this interface in the referenced servlet.jar . There is also servlet.jar in J2EE , and this method does exist in the servletResponse interface in this jar package . But how to make the project reference this interface in the first place? First delete the reference to servlet.jar , and then add it again.

问题可以解决。但是真的需要每次遇到这个问题都这样吗?难道myEclipse针对兄的jar包,就没有控制引用顺序的方法吗,答案是由。

解决方案3

打开buildpath,切换到Order and Export 选项卡,把J2EE的库移至前边即可,如下图。就这么简单。

 setCharacterEncoding未定义 - 石小永-信息提高班 - 石小永 廊坊师范学院七期信息技术提高班

 

 

总结:之所以出现setCharacterEncoding未定义的错误,是因为引入(或者说使用)的jar包没有这个方法,是真的没有。而有这个方法的jar包又没有被引入。删除错误的jar包固然是个解决办法,但如果有很多个冲突的jar包,或者这些jar包之间不仅仅是版本的关系的时候,使用更改引用顺序将会是一种更好的方法。

 

之后又遇到了个isWrapperFor 方法未定义的错误。有了上次的经验,去同事那看了下,他那引用的是rt.jar,而我这引用的是class12.jar(我们的jar包是相同的),之索引出现这种问题,可能是引用的顺序造成的。更爱了引用顺序后,然后错误就消失了

 

 

方法3 亲测可行。

感谢博主 http://sxyandapp.blog.163.com/blog/static/61488308201282492739161/

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327028980&siteId=291194637