JSP图片上传/放大缩小/裁减的源代码

JSP图片上传/放大缩小/裁减的源代码
JSP图片上传/放大缩小/裁减的源代码

3000分求JSP 图片上传/放大缩小/裁减的源代码

guest

dsf

竹省省市滋发息

铜牌会员

1 # 大 中 小 发表于 2009-08-27 10:33:00

3000分求JSP 图片上传/放大缩小/裁减的源代码。

能裁减固定大小比如(120*100)的就行。有预览,能显示图片

长宽和大小(file size)最好。

本人结帖率是99.87%, 可用分8000+

非常感谢!!

如果没有JSP 源代码,PHP 源代码也可以。

package myBean; import java.io.*; public class uploadpic {

String picPath;//图片路径 (如:F:picturea.gif ) public String pictype[];//设置图片的后缀名 FileInputStream in; int piclength;//设置图片的最大kb public void setpicPath(String picPath)//获得图片的路径 {

this.picPath=picPath; } 设置图片的最大长

{

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

{

if(picPath.endsWith(pictype))

return true;

}

return false;

}

return false;

}

}

以下是在jsp页面中调用uploadpic

首先要引入此bean所在的包

<%@page import="myBean.uploadpic" %>

下一条语句是得到上一层页面,也就是用户提交的图片路径!

picp=codetostring.codeToString(request.getParameter("picPath")

);

pic.setpicPath(picp);

pic.setpiclength(100);//以kb为单位

if(pic.testlength())

out.print("length ok
");

else

out.print("length ok");

String p1,p2;

p1=".jpg";

p2=".gif";

String[] type={p1,p2};

pic.setpictype(type);

if(pic.testpictype())

out.print("typeok");

else

out.print("type error");

made by zonecens https://www.360docs.net/doc/c011512401.html,

不知道2楼的怎么样,我来学习一个!

帮顶!

好像百度一招很多

百度一下,找到相关网页约11,400,000篇,用时0.036秒

3000连个星星都升不了

这个是JAVA代码

package ftp;

import https://www.360docs.net/doc/c011512401.html,.ftp.*;

import https://www.360docs.net/doc/c011512401.html,.*;

import java.awt.*;

import java.awt.event.*;

import java.applet.*;

import java.io.*;

class FTP

extends 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.fill = GridBagConstraints.HORIZONTAL; ( (GridBagLayout) getLayout()).setConstraints(LblP

rompt, GBC);

add(LblPrompt);

GBC.gridwidth = 1;

( (GridBagLayout) getLayout()).setConstraints(LblH

ost, GBC);

add(LblHost);

GBC.gridwidth = GridBagConstraints.REMAINDER; ( (GridBagLayout) getLayout()).setConstraints(TxtH

ost, GBC);

add(TxtHost);

GBC.gridwidth = 1;

( (GridBagLayout) getLayout()).setConstraints(LblU

ID, GBC);

add(LblUID);

GBC.gridwidth = 1;

( (GridBagLayout) getLayout()).setConstraints(TxtU

ID, GBC);

add(TxtUID);

GBC.gridwidth = 1;

( (GridBagLayout) getLayout()).setConstraints(LblP

WD, GBC);

add(LblPWD);

GBC.gridwidth = 1;

( (GridBagLayout) getLayout()).setConstraints(TxtP

WD, GBC);

add(TxtPWD);

GBC.gridwidth = 1;

GBC.weightx = 2;

( (GridBagLayout) getLayout()).setConstraints(BtnC

onn, GBC);

add(BtnConn);

GBC.gridwidth = GridBagConstraints.REMAINDER;

( (GridBagLayout) getLayout()).setConstraints(BtnC

lose, GBC);

add(BtnClose);

GBC.gridwidth = GridBagConstraints.REMAINDER;

GBC.fill = GridBagConstraints.HORIZONTAL;

( (GridBagLayout) getLayout()).setConstraints(lsAr

ea, 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) {

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 = https://www.360docs.net/doc/c011512401.html,stIndexOf(fg);

String filename = filepathname.substring(

index + 1);

File localFile;

localFile = new File(filepathname); RandomAccessFile sendFile = new RandomAc

cessFile(filepathname, "r");

//

sendFile.seek(0);

outs = aftp.put(filename);

outputs = new DataOutputStream(outs); while (sendFile.getFilePointer() < sendFi

le.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() {

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下载

Java Web Start application

FTP下载

3楼 2004-10-13 09:21 szabo [引用] [回复]

angel7532(卡卡西):

哪我服务器上要不要作一些配置或安装其他软件呢?

4楼 2004-10-15 09:30 szabo [引用] [回复] 不能沉啊。。。。。。。。。

哪位还能讲讲都需要哪些准备工作呀??????

5楼 2004-10-18 08:40 szabo [引用] [回复]

真的没有人理了吗?

6楼 2004-10-18 08:58 gjd111686 [引用] [回复]

服务器是否允许安装FTP站点?

7楼 2004-10-18 09:00 gjd111686 [引用] [回复]

客户端可以用JS来完成下载,上传可以通过 来上传

具体服务器处理可以参考

[https://www.360docs.net/doc/c011512401.html,/gjd111686/archive/2004/08/18/78324.aspx]

学习

学习

楼主自在网上搜一下相似的,自己加工一下可以做成的而且可以学习很

多东西,还有别人的代码

哈看在这么多分的份上顶一个……

重金之下,毕有猛夫!

https://www.360docs.net/doc/c011512401.html,/source/1497016/

眼热啊~~~

众虎之争啊,我来UP下

1.action

package https://www.360docs.net/doc/c011512401.html,asis.action;

import java.io.BufferedInputStream;

import java.io.BufferedOutputStream;

import java.io.File;

import java.io.FileOutputStream;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import javax.servlet.http.HttpSession;

import https://www.360docs.net/doc/c011512401.html,mons.beanutils.BeanUtils;

import org.apache.struts.action.ActionForm;

import org.apache.struts.action.ActionForward;

import org.apache.struts.action.ActionMapping;

import org.apache.struts.actions.MappingDispatchAction;

import org.apache.struts.upload.FormFile;

import https://www.360docs.net/doc/c011512401.html,asis.domain.CollegeInfo;

import https://www.360docs.net/doc/c011512401.html,asis.domain.Student;

import https://www.360docs.net/doc/c011512401.html,asis.form.StudentForm;

import https://www.360docs.net/doc/c011512401.html,asis.form.UploadPicForm;

import https://www.360docs.net/doc/c011512401.html,asis.service.CollegeInfoService;

import https://www.360docs.net/doc/c011512401.html,asis.service.StudentService;

import https://www.360docs.net/doc/c011512401.html,asis.utils.ImageCut;

public class RegisterAction extends MappingDispatchAction{

private 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, ActionForm

form,

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();

//-- 如果浏览框中的文件名为空,则返回本页面

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 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("picurl",

"/"+student.getLoginName()+"/"+fileName);

return mapping.findForward("success");

}

//裁剪照片

public ActionForward saveIcon(ActionMapping mapping, ActionForm

form,

HttpServletRequest request, HttpServletResponse response)

throws Exception {

HttpSession session = request.getSession();

Student student = (Student)session.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.valueOf(request.getParameter("txt_DropHeight"))/zoom;

String name = request.getParameter("filename");

x=x <0?0:x;

y=y <0?0:y;

ImageCut imageCut = new

ImageCut((int)y,(int)x,(int)width,(int)height);

String path="student\\"+student.getLoginName();

path=this.getServlet().getServletContext().getRealPath(path);

name=name.split("/")[2];

imageCut.setSrcpath(path+"\\"+name);

imageCut.setSubpath(path+"\\"+name);

request.setAttribute("step", 3);

request.setAttribute("picurl","/"+student.getLoginName()+"/"+n

ame);

imageCut.cut();

student.setIconPath("/EduAsis/student/"+student.getLoginName()

+"/"+name);

ss.updateStudent(student);

return mapping.findForward("success");

}

//注册个人信息:

public ActionForward regtwo(ActionMapping mapping, ActionForm

form,

HttpServletRequest request, HttpServletResponse response)

throws Exception {

request.setCharacterEncoding("utf-8");

StudentForm sf = (StudentForm)form;

Student student = new Student();

BeanUtils.copyProperties(student,sf);

String collegeName = sf.getCollegeName();

String departmentName = sf.getDepartmentName();

System.out.println("departmentName"+departmentName);

CollegeInfo collegeInfo =

cs.findCollege(collegeName,departmentName);

student.setCollegeInfo(collegeInfo);

ss.addStudent(student);

HttpSession session = request.getSession();

session.setAttribute("user", student);

return mapping.findForward("success");

}

}

2 工具类

package https://www.360docs.net/doc/c011512401.html,asis.utils;

import java.awt.Rectangle;

import java.awt.image.BufferedImage;

import java.io.File;

import java.io.FileInputStream;

import java.io.IOException;

import java.util.Iterator;

import javax.imageio.ImageIO;

import javax.imageio.ImageReadParam;

import javax.imageio.ImageReader;

import javax.imageio.stream.ImageInputStream;

public class ImageCut{

private String srcpath ;

private String subpath ;

private int x ;

private int y ;

private int width ;

private int height ;

public ImageCut(){

}

public ImageCut(int x,int y,int width,int height){

this.x = x ;

this.y = y ;

this.width = width ;

this.height = height ;

}

public void cut() throws IOException{

FileInputStream is = null ;

ImageInputStream iis =null ;

try{

is = new FileInputStream(srcpath);

Iterator it =

ImageIO.getImageReadersByFormatName("jpg");

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 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 void setX(int x){

this.x = x;

}

public int getY(){

return y;

}

public void setY(int y){

js实现图片上传前的预览

js实现图片上传前的预览,实现完美兼容Firefox3,IE6,IE7,IE8和IE9的显示问题 1、脚本,把下面代码加到与之间 Js代码 1.

C++ MFC各控件代码练习例子

void CMy122Dlg::OnButton1open() { m_OPEN.EnableWindow(false ); //EnableWindow()方法可以使按钮失效 MessageBox("已打开"); m_CLOSE.EnableWindow(true ); } void CComboboxDlg::Onmony() { UpdateData(TRUE); CString str,strmoy; strmoy.Format("%d",m_money); str="你确定要将"; str+=strmoy; str+="元打入对方账户?"; if (IDOK==MessageBox(str,"提示",MB_ICONQUESTION|MB_OKCANCEL)) { MessageBox("付款成功","提示",MB_ICONASTERISK); } } 控制显示的文本利用成员函数SetWindowText/GetWindowText 用于设置/得到当前显示的文本。 通过GetLimitText/SetLimitText 可以得到/设置在输入框中输入的字符数量。 输入框几种常用的消息映射宏: ON_EN_CHANGE 输入框中文字更新后产生 ON_EN_ERRSPACE 输入框无法分配内存时产生 ON_EN_KILLFOCUS / ON_EN_SETFOCUS 在输入框失去/得到输入焦点时产生 在创建滚动条后需要调用void SetScrollRange( int nMinPos, int nMaxPos, BOOL bRedraw = TRUE )设置滚动范围, int GetScrollPos( )/int SetScrollPos( )用来得到和设置当前滚动条的位置。 void ShowScrollBar( BOOL bShow = TRUE );用来显示/隐藏滚动条。 BOOL EnableScrollBar( UINT nArrowFlags = ESB_ENABLE_BOTH )用来设置滚动条上箭头是否为允许状态。nArrowFlags 可取以下值: ESB_ENABLE_BOTH 两个箭头都为允许状态 ES_DISABLE_LTUP 上/左箭头为禁止状态 MessageBox("这个是自定义的消息!!!" ,"自定义消息对话框!!!",MB_ICONINFORMATION); MB_ABORTRETRYIGNORE 显示终止重试或忽然按钮 MB_OK 显示确定按钮 MB_RETRYCANCEL 显示确定或取消按钮 MB_YESNO 显示重试或取消按钮 MB_YESNOCANCEL 显示是或否按钮 MB_ICONQUESTION 带问号图标 MB_ICONHAND 、MB_ICONSTOP 、MB_ICONERROR 三种都是带叉号图标 MB_ICONEXCLAMA TION 、MB_ICONW ARNING 两种都是带感叹号图标 MB_ICONASTERISK MB_ICONINFORMA TION 带信息号图标 AfxMessageBox()函数缺点就无法设置消息对话框的标,提示消息框的标题与工程名称相同, 优点:就是在动态链接库工程或其它工程中,可以直接用它来显示消息提示对话框。 MessageBox()函数必须用于一个窗口对象,没有窗口对象,就无法调用MessageBox()函数

js实现图片展示效果

10款动感图片展示js代码-效果预览(10)