那有支持图片上传的组件???各位帮忙了!!!

Explorer22 2003-08-20 10:11:00
那有支持图片上传的组件???各位帮忙了!!!
可以免费下载的,或有或有原码的???
...全文
38 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
lynx1111 2003-08-22
  • 打赏
  • 举报
回复
给个简单的:

<%@ page language="java" import="com.jspsmart.upload.*"%>
<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />

<HTML>
<BODY BGCOLOR="white">

<H1>jspSmartUpload : Sample 2</H1>
<HR>

<%

String name = (String) session.getValue("username");

// Variables
int count=0;

// Initialization

mySmartUpload.initialize(pageContext);

// Upload
mySmartUpload.upload();

// Select each file
for (int i=0;i<mySmartUpload.getFiles().getCount();i++){

// Retreive the current file
com.jspsmart.upload.File myFile = mySmartUpload.getFiles().getFile(i);

// Save it only if this file exists
if (!myFile.isMissing()) {

// Save the files with its original names in a virtual path of the web server
myFile.saveAs("/upload/" + myFile.getFileName());
// myFile.saveAs("/upload/" + myFile.getFileName(), mySmartUpload.SAVE_VIRTUAL);

// sample with a physical path
// myFile.saveAs("c:\\temp\\" + myFile.getFileName(), mySmartUpload.SAVE_PHYSICAL);

// Display the properties of the current file
out.println("FieldName = " + myFile.getFieldName() + "<BR>");
out.println("Size = " + myFile.getSize() + "<BR>");
out.println("FileName = " + myFile.getFileName() + "<BR>");
out.println("FileExt = " + myFile.getFileExt() + "<BR>");
out.println("FilePathName = " + myFile.getFilePathName() + "<BR>");
out.println("ContentType = " + myFile.getContentType() + "<BR>");
out.println("ContentDisp = " + myFile.getContentDisp() + "<BR>");
out.println("TypeMIME = " + myFile.getTypeMIME() + "<BR>");
out.println("SubTypeMIME = " + myFile.getSubTypeMIME() + "<BR>");

count ++;


}

}

// Display the number of files which could be uploaded
out.println("<BR>" + mySmartUpload.getFiles().getCount() + " files could be uploaded.<BR>");

// Display the number of files uploaded
out.println(count + " file(s) uploaded.");


%>
<%

%>
</BODY>
</HTML>
Explorer22 2003-08-22
  • 打赏
  • 举报
回复
各位帮忙看一下:
第一个页面的代码:upload1.jsp

<%@ page contentType="text/html; charset=gb2312"
import="java.util.Date ,java.io.*,java.lang.*,java.text.SimpleDateFormat"%>
<HTML>
<BODY BGCOLOR="white">

<H1 align="center">图片、电影、音乐、新闻上传</H1>
<HR>

<FORM METHOD="POST" ACTION="/programe/uploadFile/upload.jsp" ENCTYPE="multipart/form-data">
<select name="Type" size="1" > //*****这是要传送的值“Type"********
<%

String path="";

path = request.getRealPath("./");

File d = new File(path);
//建立代表目前目录位置的File件, 并由d件变数引用

File list[] = d.listFiles();
//取得代表目录中所有文件的File件阵列
int j=list.length-3;
int i =0;
while(j>0)
{

%>
<option value="<%=list[i]%>"><%=list[i]%></option>
<%
i++;
j--;
}
%>
</select>
<select name="Year" size="1">
<%
Date today = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
String sToday = format.format(today);
int lToday = Integer.parseInt(sToday);
int w = lToday%10000;
int ww=(lToday-w)/10000;

%>
<option value="<%=String.valueOf(ww)%>"><%=String.valueOf( ww)%></option>
</select>
<select name="Month" size="1">
<%
for(int month=1;month<=12;month++)
{
%>
<option value="<%=String.valueOf(month)%>"><%=String.valueOf( month)%></option>
<%
}
%>
</select>
<select name="Day" size="1">
<%
for(int day=1;day<=31;day++)
{
%>
<option value="<%=String.valueOf(day)%>"><%=String.valueOf(day)%></option>
<%
}
%>
</select>

<br>
<INPUT TYPE="FILE" NAME="FILE1" SIZE="50"><BR>
<INPUT TYPE="FILE" NAME="FILE2" SIZE="50"><BR>
<INPUT TYPE="FILE" NAME="FILE3" SIZE="50"><BR>
<INPUT TYPE="FILE" NAME="FILE4" SIZE="50"><BR>
<INPUT TYPE="SUBMIT" VALUE="Upload">
</FORM>

</BODY>
</HTML>

第二个页面的代码:upload.jsp
<%@ page contentType="text/html; charset=gb2312" language="java"
import="com.jspsmart.upload.*,java.io.File,java.lang.*,java.util.Date,java.text.SimpleDateFormat"%>
<jsp:useBean id="mySmartUpload" scope="page" class="com.jspsmart.upload.SmartUpload" />


<HTML>
<head>
<title>Images,Movies,Music,News UpLoaded</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

</head>

<BODY BGCOLOR="white">

<H1 align="center">Images,Movies,Music,News UpLoaded</H1>
<HR>

<%

String type = request.getParameter("Type"); //********这是接收这个传送的值**
//String year = request.getParameter("Year");
//String month =request.getParameter("Month");
//String day = request.getParameter("Day");
out.println(type);

String path="";

path = request.getRealPath("./");

File d = new File(path);
//建立代表目前目录位置的File件, 并由d件变数引用

File list[] = d.listFiles();
//取得代表目录中所有文件的File件阵列
%>

<%
// Variables
int count=0;

// Initialization
mySmartUpload.initialize(pageContext);

// Only allow txt or htm files
mySmartUpload.setAllowedFilesList(" gif,jpg,swf,txt");

// DeniedFilesList can also be used :
// mySmartUpload.setDeniedFilesList("exe,bat,jsp");

// Deny physical path
// mySmartUpload.setDenyPhysicalPath(true);

// Only allow files smaller than 2000000 bytes
mySmartUpload.setMaxFileSize(2000000);

// Deny upload if the total fila size is greater than 800000 bytes
mySmartUpload.setTotalMaxFileSize(800000);

// Upload
mySmartUpload.upload();

//look for file path ,if there is nothing ,create file path
File myFilePath = new File(type);
if(!myFilePath.exists())
myFilePath.mkdir();

String nextFilePath="";
nextFilePath = request.getRealPath("myFilePath/");


Date today = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
String sToday = format.format(today);



String fileName =sToday;
File myFile = new File(nextFilePath+"/"+fileName);
if(!myFile.exists())
myFile.mkdir();
String filePath = nextFilePath+"/"+fileName;

// Save the files with their original names in a virtual path of the web server
try {

count = mySmartUpload.save(filePath, mySmartUpload.SAVE_VIRTUAL);

} catch (Exception e){

out.println("<b>Wrong selection : </b>" + e.toString());

}

// Display the number of files uploaded
out.println(count + " file(s) uploaded.");

%>


<table width="85%" border="0" cellpadding="3" cellspacing="0">
<tr>
<td colspan="8">在<Font color = red><%= path%></Font>目录下的文件 一共有 <font color="#FF0000"><%=list.length%></font>
个文件或目录  <a href="javascript:history.back(1)">返回</a>   <a href="javascript:location.reload()">刷新</a> </td>
</tr>
</table>
<hr>

<table width="1000" height="150"border="0" align="center" cellpadding="3" cellspacing="0">
<%
for(int i=0; i <list.length/5; i++)
{
%>
<tr >
<%
for(int j=0;j<5;j++)
{
File f = new File(path,list[i*5+j].getName());
String file="";

file=list[i*5+j].getName();

//out.print(file.toString());
%>
<td align="center" width="120" height="150">
<a href="<%=file%>" target="_self"><img src="<%=file%>" width="120" height="150" name="<%=file.toString()%>" title="<%=file.toString()%>" ></a>
<a href="<%=file%>" target="_parent"><%=file%></a>
</td>
<%
}
%>
</tr>
<%
}
%>
</table>
<BR>
<a href="javascript:history.back(1)">Back</a>
</BODY>
</HTML>
大家帮忙看看为什么传过来的值接收后为空????在线等!!!!急啊!!!!!!!!!!!!


gboy2003 2003-08-22
  • 打赏
  • 举报
回复
jspsmartupload
mingjob 2003-08-21
  • 打赏
  • 举报
回复
在upload.jsp页面的第47行发生,一般都是因为变量没有赋到值就引用而引起。
解决:在使用变量之前判断是否为null
Explorer22 2003-08-21
  • 打赏
  • 举报
回复
在问大家一个问题!!!
500 Servlet Exception
java.lang.NullPointerException
at java.io.File.<init>(File.java:180)
at _programe._uploadfile._upload__jsp._jspService (/programe/uploadFile/upload.jsp:47)
at com.caucho.jsp.JavaPage.service(JavaPage.java:75)
这样的异常怎么解决???由什么引起的,应该怎么着手解决???
我用的是resin,请各位帮忙了!!!!
lynx1111 2003-08-20
  • 打赏
  • 举报
回复

http://www.csdn.net/develop/Read_Article.asp?Id=18987
wdmsyf 2003-08-20
  • 打赏
  • 举报
回复
jspsmartupload

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧