为什么这段代码在火狐中不显示,upload.jsp不能加载进来,但在其他浏览器上都可以正常显示,请求高手帮帮忙!先谢谢了!!我把全部相关的代码贴出来!
1.jsp的部分代码如下:
<script language="javascript" type="text/javascript"   >
var imgUploader = new ImageUploader(); imgUploader.Config["PostUrl"]="http://localhost:8080/MZLHRZ/imgupload/upload.jsp";
imgUploader.Fields["UserID"] = "dsh";
window.onload = function()
{
imgUploader.Init();
};
</script>
2.ImageUploader.css如下:
function ImageUploader()
{
this.Com = null;
this.Domain = "http://" + document.location.host;
this.Config = {
"EncodeType" : "GB2312"
, "Licensed" : ""
, "ThumbWidth" : "0"
, "ThumbHeight" : "0"
, "ImageUploadType" : ""
, "Water" : false
, "ClsidUploader" : "2025D1D7-921B-49bd-8073-7C64ABFDFFD4"
, "AppPath" : "/"
, "CabPath" : ""
, "PostUrl" : ""
};
this.Fields = {
"UserID": "102"
};
this.InitPath = function()
{
this.Domain += this.Config["AppPath"];
this.Config["PostUrl"] = this.Domain + this.Config["PostUrl"];
this.Config["CabPath"] = this.Domain + this.Config["CabPath"];
};
this.Load = function()
{
//this.InitPath();
var acx = '<object id="objImageUploader" classid="clsid:' + this.Config["ClsidUploader"] + '"';
acx += ' codebase="' + this.Config["CabPath"] + '" width="580" height="200"></object>';
document.write(acx);
};
this.Load();
this.Init = function()
{
try
{
this.Com = document.getElementById("objImageUploader");
this.Com.Object = this;
this.Com.PostUrl = this.Config["PostUrl"];
this.Com.EncodeType = this.Config["EncodeType"];
this.Com.Licensed = this.Config["Licensed"];
this.Com.ThumbnailWidth = this.Config["ThumbWidth"];
this.Com.ThumbnailHeight = this.Config["ThumbHeight"];
this.Com.ImageUploadType = this.Config["ImageUploadType"];
this.Com.Water = this.Config["Water"];
this.Com.AfterImagesPosted = AfterImagesPosted;
this.Com.OnError = ImageUploader_OnError;
for (var name in this.Fields)
{
this.Com.AddField(name, this.Fields[name]);
}
}
catch (e)
{ }
};
this.UpdateFields = function()
{
if (null == this.Com) return; this.Com.ClearFields();
for (var name in this.Fields)
{
this.Com.AddField(name, this.Fields[name]);
}
};
this.SetDefaultFolder = function(path)
{
this.Com.DefaultFolder = path;
};
}
function ImageUploader_OnError(obj)
{
alert(obj.Com.Response);
}
function AfterImagesPosted(obj)
{
var imgs = obj.Com.GetPostedFiles();
if (imgs == null) return;
var strImgs = new Array(); for (var index = imgs.lbound(1); index <= imgs.ubound(1); index++)
{
strImgs.push(imgs.getItem(index));
} var msg = document.getElementById("msg");
msg.innerHTML = strImgs.join("<br/>");
}
3、upload.jsp代码如下:
<%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
<%@ page import="Xproer.Uploader" %>
<%
com.jspsmart.upload.SmartUpload su = new com.jspsmart.upload.SmartUpload();
su.initialize(pageContext);
su.upload();
com.jspsmart.upload.File file = su.getFiles().getFile(0);
String userName = su.getRequest().getParameter("UserName");

Uploader up = new Uploader(pageContext,request);
up.SaveFile(file);
out.write(up.GetFilePathRel());
%>
4、Uploader.java代码如下:
public class Uploader {

public PageContext m_pc;
String m_folder;
String m_curBasePath;
String m_filePathRel;
String m_fileName;
public Uploader(PageContext pc,HttpServletRequest sr)
{
this.m_pc = pc;
String path = sr.getContextPath();
//this.m_curBasePath = sr.getScheme()+"://" + sr.getServerName()+":" + sr.getServerPort() + path+"/";
this.m_curBasePath = path+"/";
}
public String GetFilePathRel()
{
return this.m_filePathRel + this.m_fileName;
}
public void CreateFolder()
{
Date timeCur = new Date();
String pathRel = "pho/" + "renyuan/" ;
String pathAbs = "pho\\" + "renyuan/" + "\\" ;
this.m_filePathRel = this.m_curBasePath + pathRel;
this.m_folder = this.m_pc.getServletContext().getRealPath("/") + pathAbs;
File f = new File(this.m_folder);
if(!f.exists())
{
f.mkdirs();
}
}
public String GenerateFileName()
{
Date timeCur = new Date();
SimpleDateFormat fmt = new SimpleDateFormat("HHmmssSSSS");
String timeStr = fmt.format(timeCur);
return timeStr;
}
public void SaveFile(com.jspsmart.upload.File upFile)
{

this.m_fileName = this.GenerateFileName() + "." + upFile.getFileExt();

this.CreateFolder();
String filePath = this.m_folder + this.m_fileName; 
try {
upFile.saveAs(filePath);
} catch (SmartUploadException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
百度下有说将language去掉,也不行!只知道火狐有的代码不支持,但是具体哪不支持怎么也找不出来,请知道的大虾们帮帮忙吧!!javascript不显示火狐不支持javascript