首页后端开发其他后端知识用jsp编写文件上载

用jsp编写文件上载

时间2024-02-07 21:30:03发布访客分类其他后端知识浏览844
导读:收集整理的这篇文章主要介绍了用jsp编写文件上载,觉得挺不错的,现在分享给大家,也给大家做个参考。 如果你曾用vb编写文件上传的组件的话,那么用JAVA编写文件上传的JAVABEAN十分...
收集整理的这篇文章主要介绍了用jsp编写文件上载,觉得挺不错的,现在分享给大家,也给大家做个参考。 如果你曾用vb编写文件上传的组件的话,那么用JAVA编写文件上传的JAVABEAN十分容易。
下面的例子只是一个简版
package yuanyifileup;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.PageContext;

public class yuanyifileup
{
PRivate ServletRequest request;
private ServletResponse response;
private Servletconfig config;
ServletInputStream DATA;
int FormSize;
File F1;
FileOutputStream os;
DatainputStream is;
String filename;
byte[] b;
byte t;
boolean flag=false;
public yuanyifileup()
{ }
public void inITialize(ServletConfig config,HttpServletRequest request,HttpServletResponse response) throws IOException
{
this.request=request;
this.response=response;
this.config=config;
DATA = request.getInputStream();
FormSize=request.getContentLength();
}
public void initialize(PageContext pageContext) throws IOException
{
request=pageContext.getRequest();
response=pageContext.getResponse();
config=pageContext.getServletConfig();
DATA = request.getInputStream();
FormSize=request.getContentLength();
}
public boolean setFilename(String s)
{
try
{
File f1=new File(s);
os=new FileOutputStream(f1);
}
catch(IOException e)
{ return(false); }
return(true);
}
public void getByte()
{
int i=0;
try
{
is=new DataInputStream(DATA);
b=new byte[FormSize];

while (true)
{
try
{
t=is.readByte();
b[i]=t;
i++;
}
catch(EOFException e)
{ break; }
}
is.close(); }
catch(IOException e)
{ }
}

public boolean save()
{
int i=0,start1=0,start2=0;
String temp="";
if (!flag)
{
getByte();
flag=true;
}
try
{
temp=new String(b,"ISO8859_1");
}
catch(UnsupportedEncodingException e)
{ return(false); }

start1=temp.indexOf("image/");
temp=temp.substring(start1);

start1=temp.indexOf("\r\n\r\n");

temp=temp.substring(start1+4);
start2=temp.indexOf("; \r\n");
if (start2!=-1)
{
temp=temp.substring(0,start2);
}
try
{
byte[] img=temp.getBytes("ISO8859_1");
for (i=0; iimg.length; i++)
{ os.write(img[i]); }
os.close();
}
catch(IOException e)
{ return(false); }

return(true);

}
如果有不明白的发E-Mail:yymailbox@263.net.Bye

}

您可能感兴趣的文章:
  • 用JSP编写文件上传
  • C#读写文件的方法汇总
  • php中读写文件与读写数据库的效率比较分享
  • php中并发读写文件冲突的解决方案
  • php多用户读写文件冲突的解决办法
  • Java读写文件创建文件夹多种方法示例详解
  • python读写文件操作示例程序
  • c++读写文件流实例程序讲解
  • 三种Node.js写文件的方式

声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!


若转载请注明出处: 用jsp编写文件上载
本文地址: https://pptw.com/jishu/604582.html
用JSP编写文件上传 在JSP中处理虚拟路径

游客 回复需填写必要信息