JSP图片上传放大缩小裁减的源代码Word格式.docx
- 文档编号:5223172
- 上传时间:2023-05-04
- 格式:DOCX
- 页数:52
- 大小:122.21KB
JSP图片上传放大缩小裁减的源代码Word格式.docx
《JSP图片上传放大缩小裁减的源代码Word格式.docx》由会员分享,可在线阅读,更多相关《JSP图片上传放大缩小裁减的源代码Word格式.docx(52页珍藏版)》请在冰点文库上搜索。
有预览,能显示图片长宽和大小(filesize)最好。
本人结帖率是99.87%,
可用分8000+
非常感谢!
!
如果没有JSP源代码,PHP源代码也可以。
packagemyBean;
importjava.io.*;
publicclassuploadpic{
StringpicPath;
//图片路径(如:
F:
picturea.gif)
publicStringpictype[];
//设置图片的后缀名
FileInputStreamin;
intpiclength;
//设置图片的最大kb
publicvoidsetpicPath(StringpicPath)//获得图片的路径
{
this.picPath=picPath;
}
publicvoidsetpiclength(intpiclength)//设置图片的最大长度
this.piclength=piclength;
publicintgetpiclength()
returnpiclength;
publicbooleantestlength()//判断图片的长度是否大于设定的最大长度
try{
in=newFileInputStream(picPath);
if(in.available()/1024>
piclength)
returnfalse;
}catch(IOExceptione)
System.out.println(e.getMessage());
returntrue;
publicvoidsetpictype(String[]pictype)//设置图片的扩展名
this.pictype=pictype;
publicbooleantestpictype()//判断图片的扩展名是否是规定的
if(pictype!
=null)
for(inti=0;
i<
pictype.length;
i)
if(picPath.endsWith(pictype))
}
以下是在jsp页面中调用uploadpic
首先要引入此bean所在的包
<
%@pageimport="
myBean.uploadpic"
%>
jsp:
useBeanid="
pic"
scope="
page"
class="
/>
下一条语句是得到上一层页面,也就是用户提交的图片路径!
Stringpicp=codetostring.codeToString(request.getParameter("
picPath"
));
pic.setpicPath(picp);
pic.setpiclength(100);
//以kb为单位
if(pic.testlength())
out.print("
lengthok<
br>
"
);
else
lengthok"
Stringp1,p2;
p1="
.jpg"
;
p2="
.gif"
String[]type={p1,p2};
pic.setpictype(type);
if(pic.testpictype())
typeok"
typeerror"
madebyzonecens
不知道2楼的怎么样,我来学习一个!
帮顶!
好像XX一招很多
XX一下,找到相关网页约11,400,000篇,用时0.036秒
3000连个星星都升不了
这个是JAVA代码
package
ftp;
import
.ftp.*;
.*;
java.awt.*;
java.awt.event.*;
java.applet.*;
java.io.*;
class
FTP
extends
Applet
{
FtpClient
aftp;
DataOutputStream
outputs;
TelnetInputStream
ins;
TelnetOutputStream
outs;
TextArea
lsArea;
Label
LblPrompt;
Button
BtnConn;
BtnClose;
TextField
TxtUID;
TxtPWD;
TxtHost;
int
ch;
public
String
a
=
"
没有连接主机"
hostname
void
init()
setBackground(Color.white);
setLayout(new
GridBagLayout());
GridBagConstraints
GBC
new
GridBagConstraints();
LblPrompt
Label("
LblPrompt.setAlignment(Label.LEFT);
BtnConn
Button("
连接"
BtnClose
断开"
BtnClose.enable(false);
TxtUID
TextField("
15);
TxtPWD
TxtPWD.setEchoCharacter('
*'
TxtHost
20);
LblUID
User
ID:
LblPWD
PWD:
LblHost
Host:
lsArea
TextArea(30,
80);
lsArea.setEditable(false);
GBC.gridwidth
GridBagConstraints.REMAINDER;
GBC.fill
GridBagConstraints.HORIZONTAL;
(
(GridBagLayout)
getLayout()).setConstraints(LblPrompt,
GBC);
add(LblPrompt);
1;
getLayout()).setConstraints(LblHost,
add(LblHost);
getLayout()).setConstraints(TxtHost,
add(TxtHost);
getLayout()).setConstraints(LblUID,
add(LblUID);
getLayout()).setConstraints(TxtUID,
add(TxtUID);
getLayout()).setConstraints(LblPWD,
add(LblPWD);
getLayout()).setConstraints(TxtPWD,
add(TxtPWD);
GBC.weightx
2;
getLayout()).setConstraints(BtnConn,
add(BtnConn);
getLayout()).setConstraints(BtnClose,
add(BtnClose);
getLayout()).setConstraints(lsArea,
add(lsArea);
}
boolean
connect(String
hostname,
uid,
pwd)
this.hostname
hostname;
LblPrompt.setText("
正在连接,请等待....."
try
aftp
FtpClient(hostname);
aftp.login(uid,
pwd);
aftp.binary();
showFileContents();
catch
(FtpLoginException
e)
无权限与主机:
+
连接!
LblPrompt.setText(a);
return
false;
(IOException
连接主机:
失败!
(SecurityException
成功!
true;
stop()
aftp.closeServer();
paint(Graphics
g)
action(Event
evt,
Object
obj)
if
(evt.target
==
BtnConn)
(connect(TxtHost.getText(),
TxtUID.getText(),
TxtPWD.getText()))
BtnConn.setEnabled(false);
BtnClose.setEnabled(true);
BtnClose)
stop();
BtnConn.enable(true);
与主机"
连接已断开!
super.action(evt,
obj);
sendFile(String
filepathname)
result
(aftp
!
=
null)
正在粘贴文件,请耐心等待...."
contentperline;
粘贴成功!
fg
String("
\"
index
filepathname.lastIndexOf(fg);
filename
filepathname.substring(index
1);
File
localFile;
localFile
File(filepathname);
RandomAccessFile
sendFile
RandomAccessFile(filepathname,
r"
//
sendFile.seek(0);
outs
aftp.put(filename);
outputs
DataOutputStream(outs);
while
(sendFile.getFilePointer()
<
sendFile.length())
ch
sendFile.read();
outputs.write(ch);
outs.close();
sendFile.close();
粘贴失败!
else
result;
showFileContents()
StringBuffer
buf
StringBuffer();
lsArea.setText("
ins
aftp.list();
(ch
ins.read())
>
0)
buf.append(
(char)
ch);
lsArea.appendText(buf.toString());
ins.close();
static
main(String
args[])
Frame
f
Frame("
FTP
Client"
f.addWindowListener(new
WindowAdapter()
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- JSP 图片 上传 放大 缩小 裁减 源代码