📄 upload2.htm
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta http-equiv="KEYWORDS" content="小龙亭工作室之JSP实践之旅">
<title>小龙亭工作室之JSP实践之旅</title>
<link rel="stylesheet" href="../jsp.css" type="text/css">
</head>
<body topmargin="0" leftmargin="0" rightmargin="0">
<div align="center"><!--以下开始小龙亭标题 -->
<script language="javascript" src="../gaptitle.js"></script>
<!--以下开始主题索引td和文章区td -->
<div
align="center"><center>
<table width="100%">
<tr>
<td colspan="2" height="10"></td>
</tr>
<tr>
<td width="20%" style="border-right: 1px solid red" valign="top" height="227"><script
language="javascript" src="manualindex.js"></script> </td>
<td width="80%" valign="top" height="227">
<p align="center"><b><font color="#FF0000" size="3">用JSP编写文件上传<br>
</font></b><br>
<p>袁毅:2000-10-23
<p><br>
如果你曾用VB编写文件上传的组件的话,那么用JAVA编写文件上传的JAVABEAN十分容易。<br>
下面的例子只是一个简版<br>
package yuanyifileup;<br>
import java.io.*;<br>
import java.util.*;<br>
import javax.servlet.*;<br>
import javax.servlet.http.*;<br>
import javax.servlet.jsp.PageContext;<br>
<br>
public class yuanyifileup<br>
{<br>
private ServletRequest request;<br>
private ServletResponse response;<br>
private ServletConfig config;<br>
ServletInputStream DATA;<br>
int FormSize;<br>
File f1;<br>
FileOutputStream os;<br>
DataInputStream is;<br>
String filename;<br>
byte[] b;<br>
byte t;<br>
boolean flag=false;<br>
public yuanyifileup()<br>
{ }<br>
public void initialize(ServletConfig config,HttpServletRequest request,HttpServletResponse response) throws IOException<br>
{<br>
this.request=request;<br>
this.response=response;<br>
this.config=config;<br>
DATA = request.getInputStream();<br>
FormSize=request.getContentLength();<br>
}<br>
public void initialize(PageContext pageContext) throws IOException<br>
{<br>
request=pageContext.getRequest();<br>
response=pageContext.getResponse();<br>
config=pageContext.getServletConfig();<br>
DATA = request.getInputStream();<br>
FormSize=request.getContentLength();<br>
}<br>
public boolean setFilename(String s)<br>
{<br>
try<br>
{<br>
File f1=new File(s);<br>
os=new FileOutputStream(f1);<br>
}<br>
catch(IOException e)<br>
{return(false);}<br>
return(true);<br>
}<br>
public void getByte()<br>
{<br>
int i=0;<br>
try<br>
{<br>
is=new DataInputStream(DATA);<br>
b=new byte[FormSize];<br>
<br>
while (true)<br>
{<br>
try<br>
{<br>
t=is.readByte();<br>
b[i]=t;<br>
i++;<br>
}<br>
catch(EOFException e)<br>
{ break;}<br>
}<br>
is.close();}<br>
catch(IOException e)<br>
{}<br>
}<br>
<br>
public boolean save()<br>
{<br>
int i=0,start1=0,start2=0;<br>
String temp="";<br>
if (!flag)<br>
{<br>
getByte();<br>
flag=true;<br>
}<br>
try<br>
{<br>
temp=new String(b,"ISO8859_1");<br>
}<br>
catch(UnsupportedEncodingException e)<br>
{return(false);}<br>
<br>
start1=temp.indexOf("image/");<br>
temp=temp.substring(start1);<br>
<br>
start1=temp.indexOf("\r\n\r\n");<br>
<br>
temp=temp.substring(start1+4);<br>
start2=temp.indexOf(";\r\n");<br>
if (start2!=-1)<br>
{<br>
temp=temp.substring(0,start2); <br>
}<br>
try<br>
{<br>
byte[] img=temp.getBytes("ISO8859_1");<br>
for (i=0;i<img.length;i++)<br>
{ os.write(img[i]); }<br>
os.close();<br>
}<br>
catch(IOException e)<br>
{return(false);}<br>
<br>
return(true);<br>
<br>
}<br>
如果有不明白的发E-Mail:yymailbox@263.net.Bye <br>
<br>
} <br>
<br>
</td>
</tr>
<!-- 以下是底边-->
<script language="javascript" src="../gapbottom.js"></script>
</center>
</body>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -