3000分求JSP图片上传放大缩小裁减的源代码
1 #大中小发表于2009-08-27 10:33:00
3000分求JSP图片上传放大缩小裁减的源代码。能裁减固定大小比如 的就行。有预览能显示图片长宽和大小file size)最好。
本人结帖率是99.87%, 可用分 +
dsf 如果没有JSP源代码 PHP源代码也可以。
String picPath;//图片路径 如:F:picturea.gifpublic String pictype[] ;//设置图片的后缀名FileInputStream in;int piclength;//设置图片的最大kb
}
public void setpiclength)//设置图片的最大长
{this.piclength=piclength;
}public int getpiclength()
{return piclength;
}public boolean testlength()//判断图片的长度是否大于设定的最大长度
{try{in=new FileInputStream(picPath) ;if(in.available()/1024>piclength)return false;
}catch(IOException e)
{
System.out.println(e.getMessage() ) ;
}return true;
}public void setpictype(String[] pictype)//设置图片的扩展名
{this.pictype=pictype;
}public boolean testpictype()//判断图片的扩展名是否是规定的
{if(pictype!=null)
{for(int i=0; i <pictype. length; i )
{if(picPath.endsWith(pictype) )return true;
}return false;
}return false;
}
}
以下是在jsp页面中调用uploadpic
首先要引入此bean所在的包
<%@page import="myBean.uploadpic" %>
<jsp:useBean id="pic" scope="page" class="myBean.uploadpic" />下一条语句是得到上一层页面也就是用户提交的图片路径
Stringpicp=codetostring.codeToString(request.getParameter("picPath")) ;pic. setpicPath(picp) ;pic. setpiclength(100) ;//以kb为单位if(pic. testlength() )out.print("length ok <br>") ;elseout.print("length ok") ;
String p1,p2;p1=". jpg";p2=".gif";
String[] type={p1,p2} ;pic. setpictype(type) ;if(pic. testpictype() )out.print("typeok") ;elseout.print("type error") ;made by zonecens www.okjava.net.cn
不知道2楼的怎么样我来学习一个
帮顶
好像百度一招很多
百度一下找到相关网页约11,400,000篇用时0.036秒3000连个星星都升不了
这个是JAVA代码package ftp;import sun.net.ftp.*;import sun.net.*;import java.awt.*;import java.awt.event.*;import java.applet.*;
import java. io.*;class FTPextends Applet {
FtpClient aftp;
DataOutputStream outputs;
TelnetInputStream ins;
TelnetOutputStream outs;
TextArea lsArea;
Label LblPrompt;
Button BtnConn;
Button BtnClose;
TextField TxtUID;
TextField TxtPWD;
TextField TxtHost;int ch;public String a = "没有连接主机";
String hostname = "";public void init() {setBackground(Color.white) ;setLayout(new GridBagLayout() ) ;
GridBagConstraints GBC = new GridBagConstraints() ;
LblPrompt = new Label ("没有连接主机") ;LblPrompt. setAlignment(Label.LEFT) ;BtnConn = new Button("连接") ;
BtnClose = new Button("断开") ;
BtnClose.enable(false) ;
TxtUID = new TextField("", 15) ;TxtPWD = new TextField("", 15) ;TxtPWD. setEchoCharacter('*' ) ;
TxtHost = new TextField("", 20) ;Label LblUID = new Label ("User ID:") ;Label LblPWD = new Label ("PWD:") ;Label LblHost = new Label ("Host:") ;
lsArea = new TextArea(30, 80) ;lsArea. setEditable(false) ;
GBC.gridwidth = GridBagConstraints.REMAINDER;GBC.f ill = GridBagConstraints.HORIZONTAL;( (GridBagLayout) getLayout() ) . setConstraints(LblPrompt, GBC) ;add(LblPrompt) ;
GBC.gridwidth = 1 ;
( (GridBagLayout) getLayout() ) . setConstraints(LblHost, GBC) ;add(LblHost) ;
GBC.gridwidth = GridBagConstraints.REMAINDER;( (GridBagLayout) getLayout() ) . setConstraints(TxtHost, GBC) ;add(TxtHost) ;
GBC.gridwidth = 1 ;
( (GridBagLayout) getLayout() ) . setConstraints(LblUID, GBC) ;add(LblUID) ;
GBC.gridwidth = 1 ;
( (GridBagLayout) getLayout() ) . setConstraints(TxtUID, GBC) ;add(TxtUID) ;
GBC.gridwidth = 1 ;
( (GridBagLayout) getLayout() ) . setConstraints(LblPWD, GBC) ;add(LblPWD) ;
GBC.gridwidth = 1 ;
( (GridBagLayout) getLayout() ) . setConstraints(TxtPWD, GBC) ;add(TxtPWD) ;
GBC.gridwidth = 1 ;
GBC.weightx = 2;
( (GridBagLayout) getLayout() ) . setConstraints(BtnConn, GBC) ;add(BtnConn) ;
GBC.gridwidth = GridBagConstraints.REMAINDER;( (GridBagLayout) getLayout() ) . setConstraints(BtnClose, GBC) ;add(BtnClose) ;
GBC.gridwidth = GridBagConstraints.REMAINDER;GBC.f ill = GridBagConstraints.HORIZONTAL;( (GridBagLayout) getLayout() ) . setConstraints(lsArea, GBC) ;add(lsArea) ;
}public boolean connect(String hostname, String uid,String pwd) {this.hostname = hostname;
LblPrompt. setText("正在连接请等待. . . . . ") ;try {aftp = new FtpClient(hostname) ;aftp. login(uid, pwd) ;aftp.binary() ;showFileContents() ;
}catch (FtpLoginException e) {a = "无权限与主机:" + hostname + "连接!";
LblPrompt. setText(a) ;return false;
}catch (IOException e) {a = "连接主机:" + hostname + "失败!";
LblPrompt. setText(a) ;return false;
}catch (SecurityException e) {a = "无权限与主机:" + hostname + "连接!";
LblPrompt. setText(a) ;return false;
}
LblPrompt. setText("连接主机:" + hostname + "成
功!") ;return true;
}
public void stop() {try {aftp.closeServer() ;
}catch (IOException e) {
}
}public void paint(Graphics g) {
}public boolean action(Event evt, Object obj) {if (evt. target == BtnConn) {
LblPrompt. setText("正在连接请等待. . . . . ") ;if (connect(TxtHost.getText() , TxtUID.getText() , TxtPWD.getText() ) ) {
BtnConn. setEnabled(false) ;
BtnClose. setEnabled(true) ;
}return true;
}if (evt. target == BtnClose) {
stop() ;
BtnConn.enable(true) ;
BtnClose.enable(false) ;
LblPrompt. setText("与主机" + hostname + "连
接已断开!") ;return true;
}return super.action(evt, obj) ;
}public boolean sendFile(String filepathname) {boolean result = true;if (aftp != null) {
LblPrompt. setText("正在粘贴文件,请耐心等
待. . . . ") ;
String contentperline;try {a = "粘贴成功!";
String fg = new String("\") ;int index = filepathname. lastIndexOf(fg) ;String filename = filepathname. substring(index + 1) ;
File localFile;localFile = new File(filepathname) ;RandomAccessFile sendFile = new RandomAccessFile(filepathname, "r") ;
//sendFile. seek(0) ;outs = aftp.put(filename) ;outputs = new DataOutputStream(outs) ;while (sendFile.getFilePointer() < sendFile. length() ) {ch = sendFile.read() ;outputs.write(ch) ;
}outs.close() ;sendFile.close() ;
}catch (IOException e) {a = "粘贴失败!";result = false;
}
LblPrompt. setText(a) ;showFileContents() ;
}else {result = false;
}return result;
}public void showFileContents() {StringBuffer buf = new StringBuffer() ;lsArea. setText("") ;try {ins = aftp. list() ;while ( (ch = ins.read() ) >= 0) {buf.append( (char) ch) ;
}lsArea.appendText(buf. toString() ) ;ins.close() ;
}catch (IOException e) {
}
}public static void main(String args[] ) {Frame f = new Frame("FTP Client") ;f.addWindowListener(new WindowAdapter() {
快云科技怎么样?快云科技是一家成立于2020年的新起国内主机商,资质齐全 持有IDC ICP ISP等正规商家。我们秉承着服务于客户服务于大众的理念运营,机器线路优价格低。目前已注册用户达到5000+!主营产品有:香港弹性云服务器,美国vps和日本vps,香港物理机,国内高防物理机以及美国日本高防物理机!产品特色:全配置均20M带宽,架构采用KVM虚拟化技术,全盘SSD硬盘,RAID10阵列, 国...
HostYun是一家成立于2008年的VPS主机品牌,原主机分享组织(hostshare.cn),商家以提供低端廉价VPS产品而广为人知,是小成本投入学习练手首选,主要提供基于XEN和KVM架构VPS主机,数据中心包括中国香港、日本、德国、韩国和美国的多个地区,大部分机房为国内直连或者CN2等优质线路。本月商家全场9折优惠码仍然有效,以KVM架构产品为例,优惠后韩国VPS月付13.5元起,日本东京...
农历春节将至,腾讯云开启了热门爆款云产品首单特惠秒杀活动,上海/北京/广州1核2G云服务器首年仅38元起,上架了新的首单优惠活动,每天三场秒杀,长期有效,其中轻量应用服务器2G内存5M带宽仅需年费38元起,其他产品比如CDN流量包、短信包、MySQL、直播流量包、标准存储等等产品也参与活动,腾讯云官网已注册且完成实名认证的国内站用户均可参与。活动页面:https://cloud.tencent.c...