日期:2014-05-18  浏览次数:20696 次

本机没有任何问题,到了服务器报错勒,好像是关于字符替换的
package   com.hmilyld.common;

public   class   StrEncoding   {
public   static   String   strEncoding(String   str){
str   =   str.replace( "\ " ",   " ");
str   =   str.replace( "; ",   " ");
str   =   str.replace( " ' ",   " ");
str   =   str.replace( "   ",   " ");
return   str;
}
}

就这么多东西,在本机没有任何问题,结果到了服务器后报错了,

javax.servlet.ServletException:   java.lang.String.replace(Ljava/lang/CharSequence;Ljava/lang/CharSequence;)Ljava/lang/String;
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:867)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:800)
org.apache.jsp.viewproduct_jsp._jspService(viewproduct_jsp.java:188)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
com.hmilyld.common.FilterEncoding.doFilter(FilterEncoding.java:40)

root   cause

java.lang.NoSuchMethodError:   java.lang.String.replace(Ljava/lang/CharSequence;Ljava/lang/CharSequence;)Ljava/lang/String;
com.hmilyld.common.StrEncoding.strEncoding(StrEncoding.java:5)
org.apache.jsp.viewproduct_jsp._jspService(viewproduct_jsp.java:95)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
com.hmilyld.common.FilterEncoding.doFilter(FilterEncoding.java:40)

note   The   full   stack   trace   of   the   root   cause   is   available   in   the   Tomcat   logs.


这是怎么回事?
纳闷勒,FilterEncoding.java的第40行是

chain.doFilter(request,   response);

------解决方案--------------------
java.lang.NoSuchMethodError:

public String replace(char oldChar,char newChar) //看看参数类型
或者用
public String replaceAll(String regex,String replacement)
------解决方案--------------------
检查服务器上的jre版本
String.replace方法是1.5才有的
replaceAll方法是1.4才有的