/**************************************
*Author:Java619
*Time:2005.10
**************************************/
文件上传也是我们经常用到的部件,这边我将使用Smart包,作个例子
1.上传页面index.htm
<!
DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
>
<
HTML
>
<
HEAD
>
<
TITLE
>
文件上传
</
TITLE
>
<
META
NAME
="Generator"
CONTENT
="EditPlus"
>
<
META
NAME
="Author"
CONTENT
=""
>
<
META
NAME
="Keywords"
CONTENT
=""
>
<
META
NAME
="Description"
CONTENT
=""
>
</
HEAD
>

<
BODY
>
<
FORM
METHOD
=POST
NAME
="theForm"
ACTION
=""
>
<
iframe
name
="ad"
frameborder
=0
width
=300
height
=40
scrolling
=no
src
="FileUpload.html"
></
iframe
>
</
FORM
>
</
BODY
>
</
HTML
>
2.FileUpload.html文件
<
html
>
<
head
>
<
title
>
Untitled Document
</
title
>
<
meta
http-equiv
="Content-Type"
content
="text/html; charset=gb2312"
>

<
style
type
="text/css"
>
...
<!--
body {...}{
background-color: #e8f4ff;
}
INPUT.fminpt {...}{
BORDER-TOP-WIDTH: 1px; BORDER-LEFT-WIDTH: 1px; FONT-SIZE: 9pt; BORDER-LEFT-COLOR: #466184; BACKGROUND: none transparent scroll repeat 0% 0%; BORDER-BOTTOM-WIDTH: 1px; BORDER-BOTTOM-COLOR: #466184; FONT: menu; COLOR: #e056dd; BORDER-TOP-COLOR: #466184; FONT-FAMILY: MS Shell Dlg,Tahoma, sans-serif; BORDER-RIGHT-WIDTH: 1px; BORDER-RIGHT-COLOR: #466184
}
-->
</
style
></
head
>

<
body
>


<
script
>
...
<!--
parent.theForm.Submit.disabled=false;
parent.theForm.Submit2.disabled=false;
-->
</
script
>

<
form
action
="upload.jsp"
method
="post"
enctype
="multipart/form-data"
>
<
table
><
tr
><
td
>
<
input
name
="file2"
type
="file"
class
="fminpt"
size
="20"
>
<
input
type
="submit"
class
="fminpt"
onclick
="parent.theForm.Submit.disabled=true,parent.theForm.Submit2.disabled=true"
value
="上传"
></
td
></
tr
>
</
table
>
</
form
>

</
body
>
</
html
>
3.上传处理文件upload.jsp
<%
...
@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage=""
%>

<%
...
@ page import="com.jspsmart.upload.*"
%>
<
jsp:useBean
id
="mySmartUpload"
scope
="page"
class
="com.jspsmart.upload.SmartUpload"
/>
<
html
>
<
head
>
<
title
>
上载附件
</
title
>
<
meta
http-equiv
="Content-Type"
content
="text/html; charset=gb2312"
>
</
head
>
<
body
>

<%
...

//上载附件
try
{
mySmartUpload.initialize(pageContext);
mySmartUpload.service(request,response);
mySmartUpload.upload();
String fn=fn=mySmartUpload.getFiles().getFile(0).getFileName();
mySmartUpload.save("upload/");//文件保存的目录为upload
out.println("已经成功上传了文件");
}
catch(Exception e)
{
e.printStackTrace();
}
%>
<
a
href
=FileUpload.html
>
点击确认
</
a
>
</
body
>
</
html
>
好到这边一个上传部件做好了,测试下吧!
上面用的com.jspsmart.upload包可到
或发E-mail到ceunlove@163.com索取,注明索取com.jspsmart.upload包
使用SmartUpload实现文件上传
359

被折叠的 条评论
为什么被折叠?



