?? uploadaction.java
字號(hào):
package org.apache.struts.webapp.exercise;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;
public class UploadAction extends Action {
/**
* Forward to the input form if "Save" was pressed or the main menu
* if "Cancel" was pressed.
*
* @param mapping The ActionMapping used to select this instance
* @param actionForm The optional ActionForm bean for this request
* @param request The servlet request we are processing
* @param response The servlet response we are creating
*
* @exception Exception if business logic throws an exception
*/
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
String store_path = servlet.getServletContext().getRealPath("/fileupload");
System.out.println(store_path);
UploadBean filebean = (UploadBean) form;
FormFile file = filebean.getFile();
if (file == null){
return mapping.findForward("input");
}
String filename = file.getFileName();
filebean.setFilename(filename);
String size = Integer.toString(file.getFileSize()) + "bytes";
filebean.setSize(size);
InputStream is = file.getInputStream();
OutputStream os = new FileOutputStream(store_path + "/" + filename);
int bytes = 0;
byte [] buffer = new byte[8192];
while ((bytes = is.read(buffer,0,8192))!=-1){
os.write(buffer,0,bytes);
}
os.close();
is.close();
file.destroy();
return mapping.findForward("input");
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -