📄 helloaction.java
字号:
package action;
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;
import form.HelloForm;
public class HelloAction extends Action {
public ActionForward execute(ActionMapping mapping,
ActionForm form,HttpServletRequest request,
HttpServletResponse response)
throws Exception
{
String dir = servlet.getServletContext().getRealPath("/file/");
HelloForm helloForm = (HelloForm)form;
FormFile file = helloForm.getFile();
if( file == null )
{
return mapping.findForward("failure");
}
String fileName = file.getFileName();
InputStream in = file.getInputStream();
OutputStream out = new FileOutputStream(dir + "/" + fileName);
int bytes = 0;
byte[] buffer = new byte[2048];
while(( bytes = in.read(buffer,0,2048))!=-1)
{
out.write(buffer,0,bytes);
}
return mapping.findForward("success");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -