Weblogic 8 下使用response.setCharacterEncoding("gb2312");
会报 java.lang.NoSuchMethodError: javax.servlet.http.HttpServletResponse.setCharacterEncoding(Ljava/lang/String;)V
的错误。
原因是 Weblogic 8 默认支持J2EE 1.3,J2EE 1.3 支持的Servlet版本为Servlet 2.3,而response.setCharacterEncoding 是Servlet 2.4中提供的方法,所以Weblogic会报错。
在Servlet中 使用
this.getServletContext().getMinorVersion();//子版本号
this.getServletContext().getMajorVersion();//主版本号
可以查出容器支持的servlet版。
解决方法 在response.getWriter() 方法前加上 response.setContentType("text/html;charset=gbk") 。
本文介绍了在WebLogic 8环境下使用response.setCharacterEncoding('gb2312')导致的错误及其原因。该错误源于WebLogic 8支持的Servlet版本为2.3,不包含2.4中新增的方法。文章提供了检查容器支持版本的方法,并给出了解决方案。

4567

被折叠的 条评论
为什么被折叠?



