JSP图片上传/放大缩小/裁减源代码_第1页
JSP图片上传/放大缩小/裁减源代码_第2页
JSP图片上传/放大缩小/裁减源代码_第3页
JSP图片上传/放大缩小/裁减源代码_第4页
JSP图片上传/放大缩小/裁减源代码_第5页
已阅读5页,还剩45页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、U3000分求JSP图片上传/放大缩小/裁减的源代码1 大 中 小 发表于 2009-08-27 10:33:00 - - - 3000分求JSP图片上传/放大缩小/裁减的源代码。能裁减固定大小比如(12 0*10 0)的就行。有预览,能显示图片长宽和大小(file size) 最好。本人结帖率是 99.87%, 可用分8 0 0 0+guestdsf非常感谢!如果没有JSP源代码,PHP源代码也可以。package myBea n;import java.io.*;public class uploadpic String picPath;/图片路径(如:F:picturea.gif)pub

2、lic String pictype;设置图片的后缀名FileInputStream in;省市滋发息加友in t picle ngth;/设置图片的最大kbpublic void setpicPath(Stri ng picPath)/this.picPath=picPath;获得图片的路径心讪人 口public void setpiclength(int piclength)/设置图片的最大铜牌会贝长度this.picle ngth=picle ngth;public int getpicle ngth()return picle ngth;public boolean testle ng

3、th()判断图片的长度是否大于设定的最大长度tryin=new FileInputStream(picPath);9if(in.available()/1024piclength)return false; catch(IOException e)J return true;public void setpictype(String pictype)/设置图片的扩展名 this.pictype=pictype;public boolean testpictype()/ 判断图片的扩展名是否是规定 的 if(pictype!=null) for(int i=0;i pictype.length;

4、i ) if(picPath.endsWith(pictype) return true; return false; return false;以下是在 jsp 页面中调用 uploadpic 首先要引入此 bean 所在的包 下一条语句是得到上一层页面,也就是用户提交的图片路径! String picp=codetostring.codeToString(request.getParameter(picPath); pic.setpicPath(picp);pic.setpiclength(100);/ 以 kb 为单位if(pic.testlength()out.print(length

5、 ok );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不知道 2 楼的怎么样,我来学习一个!帮顶! 好像百度一招很多 百度一下,找到相关网页约 11,400,000 篇,用时 0.036 秒 3000 连个星星都升不了这个是JAVA代码packageftp;import;import.*;im

6、portjava.awt.*;import;importjava.applet.*;importjava.io.*;classFTPextendsAppletFtpClientaftp;DataOutputStream outputs;TelnetInputStream ins;TelnetOutputStream outs;TextArea lsArea; Label LblPrompt; Button BtnConn; Button BtnClose;TextFieldTextFieldTextFieldintpublic String aTxtUID;TxtPWD;TxtHost;ch;

7、= 没有连接主机 ;String hostname public void init() setBackground(Color.white);setLayout(new GridBagLayout();GridBagConstraintsGBC = new GridBagConstraints();LblPrompt= new Label( 没有连接主机 );LblPrompt.setAlignment(Label.LEFT);BtnConn = new Button( 连接 );BtnClose = new Button( 断开 );BtnClose.enable(false);TxtUI

8、D=newTextField(,15);TxtPWD=newTextField(,15);TxtPWD.setEchoCharacter(*);TxtHost=newTextField(,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

9、.fill = 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

10、, 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 =

11、 1;( (GridBagLayout) getLayout().setConstraints(TxtPWD, GBC);add(TxtPWD);GBC.gridwidth = 1;GBC.weightx = 2;( (GridBagLayout) getLayout().setConstraints(BtnConn, GBC);add(BtnConn);GBC.gridwidthGridBagConstraints.REMAINDER;( (GridBagLayout) getLayout().setConstraints (BtnClose, GBC);add(BtnClose);GBC.

12、gridwidth = GridBagConstraints.REMAINDER;GBC.fill = GridBagConstraints.HORIZONTAL;( (GridBagLayout) getLayout().setConstraints(lsArea, GBC);add(lsArea);Stringpublic boolean connect(String hostname,uid, String pwd) this.hostname = hostname;LblPrompt.setText( 正在连接,请等待 );try aftp = new FtpClient(hostna

13、me);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 + 连接 !;LblPr

14、ompt.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.g

15、etText(), TxtUID.g etText(), 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(S

16、tringfilepathname)= true;null) 正在粘贴文件 , 请耐心等boolean resultif (aftp !=LblPrompt.setText(待);String contentperline;try a = 粘贴成功 !;String fg = new String();int index = filepathname.lastIn dexOf(fg);String filename = filepathname. substring(index + 1);File localFile;localFile = new File(filepathname);Ran

17、domAccessFile sendFile = newRandomAccessFile(filepathname, r);/sendFile.seek(0);outs = aftp.put(filename);outputs = new DataOutputStream( outs);while (sendFile.getFilePointer()= 0)buf.append( (char) ch);lsArea.appendText(buf.toString();ins.close();catch (IOException e) public static void main(String

18、 args) Frame f = new Frame(FTP Client); f.addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) System.exit(0););FTP ftp = new FTP();ftp.init();ftp.start();f.add(ftp);f.pack();f.setVisible(true); 引用 回复2楼 2004-10-13 08:56 angel7532这个是HTML网页FTP 下载 var javawsInstalled = false;v

19、ar isIE = false;var isICE = ICEBrowser) = 0;if (navigator.mimeTypes &javawsInstallednavigator.mimeTypesapplication/x-java-jnlp-file;elseisIE = true;function insertLink(url, name) if (javawsInstalled) document.write( + name + ); else if (isICE) document.write(JBuilders Web View does not support Web S

20、tart (no appropriate Web Start plugin is available).);document.write(Otherpopular(external) browsers are supported); elsedocument.write(Needto installJavaWebStart);document.write(formore information,50);visitdocument.write( ); document.write(the Java Web Start page)document.write( );on error resume

21、nextIf isIE ThenIf Not(IsObject(CreateObject(JavaWebStart.IsInstalled) ThenfalsejavawsInstalledElsejavawsInstalled = trueEnd IfEnd IfJava Web Start application FTP 下载 3楼 2004-10-13 09:21 szabo 引用 回复angel7532( 卡卡西 ):哪我服务器上要不要作一些配置或安装其他软件呢?4楼 2004-10-15 09:30 szabo 引用 回复不能沉啊。哪位还能讲讲都需要哪些准备工作呀? 引用 回复 引用

22、 回复5楼 2004-10-18 08:40 szabo真的没有人理了吗?6楼 2004-10-18 08:58 gjd111686服务器是否允许安装FTP站点?7楼 2004-10-18 09:00 gjd111686 引用 回复来上传客户端可以用 JS 来完成下载 , 上传可以通过 具体服务器处理可以参考 /archive/2004/08/18/78324.aspxfunction DownURL(strRemoteURL,strLocalURL)tryvar xmlHTTP=new ActiveXObject(Microsoft.XMLHTTP);xmlHTTP.open(Get,str

23、RemoteURL,false);xmlHTTP.send();var adodbStream=new ActiveXObject(ADODB.Stream);adodbStream.Type=1;/1=adTypeBinaryadodbStream.Open();adodbStream.write(xmlHTTP.responseBody);adodbStream.SaveToFile(strLocalURL,2);adodbStream.Close();adodbStream=null;xmlHTTP=null;/OpenFile(strLocalURL);catch(e)window.c

24、onfirm( 下载 URL 出错 !);/window.confirm( 下载完成 .);学习学习楼主自在网上搜一下相似的,自己加工一下可以做成的而且可以学习很多东西,还有别人的代码哈看在这么多分的份上顶一个 重金之下,毕有猛夫!/1497016/眼热啊 众虎之争啊,我来 UP下1.actionpackage ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import

25、 ;import ;import ;public class RegisterAction extends MappingDispatchActionprivate StudentService ss; /-private CollegeInfoService cs; /-public void setCs(CollegeInfoService cs) this.cs = cs;public void setSs(StudentService ss) this.ss = ss;/ 上传照片public ActionForward uploadPic(ActionMapping mapping,

26、 ActionFormform,HttpServletRequest request, HttpServletResponse response)throws Exception HttpSession session = request.getSession();Student student = (Student)session.getAttribute(user);UploadPicForm f = (UploadPicForm)form;FormFile ff = f.getPic(); /-String fileName=ff.getFileName();/- 如果浏览框中的文件名为

27、空,则返回本页面if(fileName.trim().equals()return mapping.findForward(fail);fileName=student.getLoginName()+.+fileName.split(.)1;String path=student+student.getLoginName();path=this.getServlet().getServletContext().getRealPath(path);File pathFile = new File(path);if(!pathFile.exists()pathFile.mkdirs();File

28、file = new File(path,fileName);BufferedInputStream bis=new BufferedInputStream(ff.getInputStream();BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream(file);int b=-1;while(b=bis.read()!=-1)bos.write(b);bis.close();bos.close();request.setAttribute(step, 2);request.setAttribute(picu

29、rl,/+student.getLoginName()+/+fileName);return mapping.findForward(success);/ 裁剪照片public ActionForward saveIcon(ActionMapping mapping, ActionFormform,HttpServletRequest request, HttpServletResponse response)throws Exception HttpSession session = request.getSession();Student student = (Student)sessio

30、n.getAttribute(user);Double zoom = Double.valueOf(request.getParameter(txt_Zoom); double x = Double.valueOf(request.getParameter(txt_top)/zoom; double y = Double.valueOf(request.getParameter(txt_left)/zoom;double width = Double.valueOf(request.getParameter(txt_DropWidth)/zoom;double height =Double.v

31、alueOf(request.getParameter(txt_DropHeight)/zoom;String name = request.getParameter(filename);x=x 0?0:x;y=y 0?0:y;ImageCut imageCut = newImageCut(int)y,(int)x,(int)width,(int)height);String path=student+student.getLoginName();path=this.getServlet().getServletContext().getRealPath(path);name=name.spl

32、it(/)2;imageCut.setSrcpath(path+name);imageCut.setSubpath(path+name);request.setAttribute(step, 3); request.setAttribute(picurl,/+student.getLoginName()+/+name);imageCut.cut(); student.setIconPath(/EduAsis/student/+student.getLoginName()+/+name);ss.updateStudent(student);return mapping.findForward(s

33、uccess);/ 注册个人信息:public ActionForward regtwo(ActionMapping mapping, ActionFormform,HttpServletRequest request, HttpServletResponse response)throws Exception request.setCharacterEncoding(utf-8);StudentForm sf = (StudentForm)form;Student student = new Student();BeanUtils.copyProperties(student,sf);Str

34、ing collegeName = sf.getCollegeName();String departmentName = sf.getDepartmentName();departmentName+departmentName);CollegeInfo collegeInfo =cs.findCollege(collegeName,departmentName);student.setCollegeInfo(collegeInfo);ss.addStudent(student);HttpSession session = request.getSession();session.setAtt

35、ribute(user, student);return mapping.findForward(success);2 工具类package ;import ;import ;import ;import ;import ;import ;import ;import ;import ;import ;public class ImageCutprivate String srcpath ;private String subpath ;private int x ;private int y ;private int width ;private int height ;public Ima

36、geCut()public ImageCut(int x,int y,int width,int height)this.x = x ;this.y = y ;this.width = width ;this.height = height ;publicvoid cut() throws IOExceptionFileInputStream is = null ;ImageInputStream iis =null ;tryis = new FileInputStream(srcpath);Iterator it =ImageIO.getImageReadersByFormatName(jp

37、g);ImageReader reader = it.next();iis = ImageIO.createImageInputStream(is);reader.setInput(iis,true) ;ImageReadParam param =reader.getDefaultReadParam();Rectangle rect = new Rectangle(x, y, width, height); param.setSourceRegion(rect);BufferedImage bi = reader.read(0,param);ImageIO.write(bi, jpg, new

38、 File(subpath); finally if(is!=null) is.close() ; if(iis!=null) iis.close(); public int getHeight() return height;public void setHeight(int height)this.height = height;public String getSrcpath()return srcpath;public void setSrcpath(String srcpath)this.srcpath = srcpath;public String getSubpath()return subpath;public void setSubpath(String subpath) this.subpath = subpath;public int getWidth()return width;public void setWidth(int width)this.width = width;public int getX()return x;public vo

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论