1、环境
tomcat6
weblogic10
ewebeditor6.2
2、问题描述
在tomcat6中上传图片一切正常,但是迁移到weblogic报错
<2009-9-24 下午12时41分25秒 CST> <Error> <HTTP> <BEA-101020> <[weblogic.servlet.internal.WebAppServletContext@5c2dd1 - appName: '_appsdir_html_dir', name: 'html', context-path: '/html', spec-version: '2.5'] Servlet failed with Exception
java.lang.StringIndexOutOfBoundsException: String index out of range: 0
at java.lang.String.charAt(String.java:687)
at com.editor.UpLoad.InitUpload(UpLoad.java:115)
at jsp_servlet._jsp.__upload._jspService(__upload.java:91)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:34)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
Truncated. see log file for complete stacktrace
>
3、问题解决
百思不得其解。查看源码跟踪,在UpLoad.java 这个文件中定位到错误。
if ((sCusDir != null)&&(sCusDir!="")) {
ch[0] = sCusDir.charAt(0);
ch[1] = sCusDir.charAt(sCusDir.length() - 1);
ch[2] = sCusDir.indexOf("./");
ch[3] = sCusDir.indexOf("/.");
ch[4] = sCusDir.indexOf("//");
for (int i = 2; i < 5; ++i)
if (ch[i] > 0)
sCusDir = "";
if ((ch[0] == 47) || (ch[0] == 46) || (ch[1] == 46))
sCusDir = "";
}
对比tomcat和weblogic运行效果,发现tomcat中是不执行这个方法的。
打印sCusDir没有任何内容
打印sCusDir.length() 长度为0
那weblogic为什么会执行这个方法呢!!!
my god!
sCusDir!=""这样的代码可是以前痛批的,怎么出现在这里呢!
改为!"".equals(sCusDir)
4、猜想
难道tomcat和weblogic处理的方式不同
5、联想到下列代码
String a="";
String b=new String ("");
System.out.println(a=="");
System.out.println(b=="");
System.out.println("".equals(a));
System.out.println("".equals(b));
很多文章多深入的探讨过怎样判断两个字符串内容是否相等!!