📄 downaccessoryaction.java
字号:
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package bugtrail.action;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DownloadAction;
import org.apache.struts.actions.DownloadAction.FileStreamInfo;
import org.apache.struts.actions.DownloadAction.StreamInfo;
import bugtrail.basic.Bug;
import bugtrail.bean.BugBean;
import bugtrail.util.CharsetProcess;
/**
* MyEclipse Struts
* Creation date: 01-06-2007
*
* XDoclet definition:
* @struts.action scope="request" validate="true"
* @struts.action-forward name="succ" path="/bugInfo.jsp"
*/
public class DownAccessoryAction extends DownloadAction {
/*
* Generated Methods
*/
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
protected StreamInfo getStreamInfo(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
String contentType="application/msword";
// Set the content disposition
String accesName=CharsetProcess.U2C((String)request.getParameter("fileName"));
// String iso_accesName=new String(accesName.getBytes("iso-8859-1"),"gb2312");
String root=servlet.getServletContext().getRealPath("/")+"file\\";
String filePath = root+accesName;
File file = new File(filePath);
// System.out.println("filePath"+filePath);
try{
FileInputStream in = new FileInputStream(filePath);
response.setContentType("application/x-msdownload;charset=GB2312");
response.setHeader("Content-Disposition","attachment; filename="
+new String(accesName));
return new FileStreamInfo(contentType,file);
}catch(FileNotFoundException e){
// todo
// ActionErrors error = new ActionErrors();
// error.add(ActionErrors.GLOBAL_ERROR,new ActionError("fileNotFound.error"));
// saveErrors(request,error);
System.out.println("附件丢失");
request.setAttribute("noFile", "noFile");
return new FileStreamInfo(contentType,file);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -