仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1327|回复: 19
打印 上一主题 下一主题

[学习教程] JAVA编程:用jsp编写文件上载

[复制链接]
愤怒的大鸟 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-18 11:31:06 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
net程序员的大部门代码都靠控件拖拽完成的,虽然java也有,但是无论从美观和速度上都没发和.net比。java程序员都是代码完成的,所以java程序员常戏称.net程序员是操作员,呵呵。js假如你曾用VB编写文件上传的组件的话,那末用JAVA编写文件上传的JAVABEAN非常简单。
上面的例子只是一个简版
packageyuanyifileup;
importjava.io.*;
importjava.util.*;
importjavax.servlet.*;
importjavax.servlet.http.*;
importjavax.servlet.jsp.PageContext;

publicclassyuanyifileup
{
privateServletRequestrequest;
privateServletResponseresponse;
privateServletConfigconfig;
ServletInputStreamDATA;
intFormSize;
Filef1;
FileOutputStreamos;
DataInputStreamis;
Stringfilename;
byte[]b;
bytet;
booleanflag=false;
publicyuanyifileup()
{}
publicvoidinitialize(ServletConfigconfig,HttpServletRequestrequest,HttpServletResponseresponse)throwsIOException
{
this.request=request;
this.response=response;
this.config=config;
DATA=request.getInputStream();
FormSize=request.getContentLength();
}
publicvoidinitialize(PageContextpageContext)throwsIOException
{
request=pageContext.getRequest();
response=pageContext.getResponse();
config=pageContext.getServletConfig();
DATA=request.getInputStream();
FormSize=request.getContentLength();
}
publicbooleansetFilename(Strings)
{
try
{
Filef1=newFile(s);
os=newFileOutputStream(f1);
}
catch(IOExceptione)
{return(false);}
return(true);
}
publicvoidgetByte()
{
inti=0;
try
{
is=newDataInputStream(DATA);
b=newbyte[FormSize];

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

publicbooleansave()
{
inti=0,start1=0,start2=0;
Stringtemp="";
if(!flag)
{
getByte();
flag=true;
}
try
{
temp=newString(b,"ISO8859_1");
}
catch(UnsupportedEncodingExceptione)
{return(false);}

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

start1=temp.indexOf("

");

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

return(true);

}

还有就是总有人问我到底该学习什么语言,什么语言有前途,那么我的回答是不论是C,C++,java,.net,ruby,asp或是其他语言都可以学,编程的关键不是语言,而是思想。
愤怒的大鸟 该用户已被删除
沙发
 楼主| 发表于 2015-2-8 15:52:07 | 显示全部楼层
是一种突破用户端机器环境和CPU
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-18 23:45

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表