日期:2014-05-19 浏览次数:20765 次
package com.yuxuan.user; import java.io.*; import java.util.*; public class Service{ private HashSet<User> users=new HashSet<User>(); public void createAccount(User user){ user.setHelloName(user.getName()+"hello"); users.add(user); } public void addImage(File file,String filename,String path)throws IOException{ FileInputStream input=new FileInputStream(file); String realpath; File outfile=new File(path); if(!outfile.exists()){ outfile.mkdir(); } realpath=outfile.getPath()+outfile.separator+filename; File outreal=new File(realpath); FileOutputStream output=new FileOutputStream(outreal); int i; while((i=input.read())!=-1){ output.write(i); } if(output!=null) output.close(); if(input!=null) input.close(); } }
package com.yuxuan; import com.opensymphony.xwork2.ActionSupport; import java.io.*; import com.yuxuan.user.*; public class updateImage extends ActionSupport{ private File pic; private String picContentType; private String picFileName; private String path; public String execute(){ try{ getService().addImage(getPic(),getPicFileName(),getPath()); }catch(IOException ex){ System.out.println(ex.getMessage()); } return SUCCESS; } public void setPath(String path){ this.path=path; } public String getPath(){ return path; } public void setPic(File pic){ this.pic=pic; } public File getPic(){ return pic; } public void setPicContentType(String picContentType){ this.picContentType=picContentType; } public String getPicContentType(){ return picContentType; } public String getPicFileName(){ return picFileName; } public void setPicFileName(String picFileName){ this.picFileName=picFileName; } public Service getService(){ return new Service(); } }
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <package namespace="/kk" name="bb" extends="struts-default"> <action name="cc" class="com.yuxuan.get"> <result name="SUCCESS">/jsp/success.jsp</result> <result name="input">/jsp/form.jsp</result> </action> <action name="inform"> <result>/jsp/form.jsp</result> </action> </package> <package namespace="/kk/secure" name="secure" extends="struts-default"> <action name="load"><result>/jsp/loadImage/image.jsp</result></action> <action name="update" class="com.yuxuan.updateImage"> <param name="path">C:/jsp/loadImage/image</param> <result>/jsp/loadImage/success.jsp</result> <result name="input">/jsp/loadImage/image.jsp</result> </action> </package> </struts>