应该是权限问题===============================================================================敏捷之源
http://www.agilesource.org提供整站下载:JAVA开源项目文档速查这就是互联网,只有不断的抄袭和改进才有进步,欢迎砸鸡蛋的朋友。
http://www.agilesource.org提供整站下载:JAVA开源项目文档速查这就是互联网,只有不断的抄袭和改进才有进步,欢迎砸鸡蛋的朋友。
这个文件夹存在吗?检查下
这个文件夹存在吗?检查下
<%@ page import="com.free.entwap.ent.*" %>
<html>
<head>
<title></title>
</head>
<body bgcolor="#ffffff">
<%
request.setCharacterEncoding("GBK");
String type_id=(String)session.getAttribute("type_id");
String ent_id= (String)session.getValue("login_id");
String text = null;
String file = null;
String priority = null;
SmartUpload mySmartUpload =new SmartUpload();
long file_size_max=400000000;
String fileName2="",ext="",testvar="";
String myFileurl="webApp/down/"; //应保证在根目录中有此目录的存在 //初始化
mySmartUpload.initialize(pageContext); //只允许上载此类文件
try {
mySmartUpload.setAllowedFilesList("jpg,gif,asf,rm,wmv,rmvb,avi,mp3,rm,wma");
//上载文件
mySmartUpload.upload();
text = mySmartUpload.getRequest().getParameter("text");
file = mySmartUpload.getRequest().getParameter("file");
String size=mySmartUpload.getRequest().getParameter("size");
String author = mySmartUpload.getRequest().getParameter("author");
System.out.println("file="+file);
com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(0);
System.out.println("text="+text);
if(myFile.isMissing())
{
%>
<script language=javascript type="">
alert("请选择图片的路径");
window.location="ent_down_web_Upload.jsp?type_id=<%=type_id%>&ent_id=<%=ent_id%> ";
</script>
<%
}
if(text==null || text.equals(""))
{
%>
<script language=javascript type="">
alert("请选择内容的格式!");
window.location="ent_down_web_Upload.jsp?type_id=<%=type_id%>&ent_id=<%=ent_id%> ";
</script>
<% }
if(author.equals(""))
{
%>
<script language=javascript type="">
alert("请填写作者");
window.location="ent_down_web_Upload.jsp?type_id=<%=type_id%>&ent_id=<%=ent_id%> ";
</script>
<%
}
if(size.equals(""))
{
%>
<script language=javascript type="">
alert("请填写文件大小");
window.location="ent_down_web_Upload.jsp?type_id=<%=type_id%>&ent_id=<%=ent_id%> ";
</script>
<%
}
//String myFileName=myFile.getFileName(); //取得上载的文件的文件名
ext= myFile.getFileExt();
System.out.print("ext============="+ext); //取得后缀名
int file_size=myFile.getSize(); //取得文件的大小
String saveurl="";
String dizhi ="";
if(file_size<file_size_max){ //更改文件名,取得当前上传时间的毫秒数值
Calendar calendar = Calendar.getInstance();
String filename = null;
filename = ent_id+String.valueOf(calendar.getTimeInMillis());
System.out.println("ssssssssssssssssssssssss"+size); String dizhiurl = com.free.entwap.Confing.getStartStr(application.getRealPath(request.getRequestURI()),request.getRequestURI())+"/"; saveurl+=filename+"."+ext;
String fileurl = null;
fileurl=ent_id+"_"+fileurl; //保存路径
dizhi = dizhiurl+myFileurl+filename+"."+ext;
myFile.saveAs(dizhi,mySmartUpload.SAVE_PHYSICAL);
String SaveFileName=request.getContextPath()+"/"+myFileurl+filename+"."+ext;
//添加图片
System.out.print("SaveFileName="+SaveFileName);
//com.free.database.PublicDBHandle mPublicDBHandle=new com.free.database.PublicDBHandle();
//mPublicDBHandle.ExecSql("insert into t_ent_down_file (ent_id,type_id,note,path,author,down_size,down_file_id) values('"+ent_id+"','"+type_id+"','"+text+"','"+SaveFileName+"','"+author+"','"+size+"',seq_down_fife_id.nextval);
DB_Web_Data dw = new DB_Web_Data();
int falg = dw.InsertDown_type(ent_id,type_id,text,SaveFileName,author,size);
if(falg==1)
{
%>
<script language=javascript type="">
alert("成功!");
window.location="ent_down_web_Upload.jsp?type_id=<%=type_id%>";
</script>
<%
}
else
{
%>
<script language=javascript type="">
alert("请把上传信息填写完整");
window.location="ent_down_web_Upload.jsp?type_id=<%=type_id%>";
</script>
<%
}
}
}
catch(Exception e){
e.printStackTrace();
%>
<script language=javascript type="">
alert("请把上传信息填写完整");
window.location="ent_down_web_Upload.jsp?type_id=<%=type_id%>";
</script>
<%
}
%>
</body>
</html>
你看看这个例子对你有帮助没
这是我最近写的一个上传文件的jsp,还能上传视频和MP3的