|
楼主 |
发表于 2016-5-24 11:33:17
|
显示全部楼层
GET http://localhost:8080/baas/hy/attachment/Classes?realFileName=undefined&storeFileName=undefined 500 (Internal Server Error)
这个是打开详细页的报错信息
- package hy;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.io.OutputStream;
- import java.sql.SQLException;
- import javax.naming.NamingException;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import com.alibaba.fastjson.JSONObject;
- import com.justep.baas.action.ActionContext;
- public class Classes {
- private static final int BUFFER_SIZE = 32768 * 8;
- public static JSONObject browsePicfile(JSONObject params, ActionContext context) throws SQLException, NamingException, IOException {
-
- System.out.println("browsePicfile is running...");
- HttpServletRequest request = (HttpServletRequest)context.get(ActionContext.REQUEST);
- HttpServletResponse response = (HttpServletResponse)context.get(ActionContext.RESPONSE);
- //String baasPath = Thread.currentThread().getContextClassLoader().getResource("").getPath() ;
- //String docStorePath = baasPath + ".." + File.separator + ".."+ File.separator + "model" +File.separator + "UI2" +File.separator + "touxiang" +File.separator+"img" ;
-
- String baasPath = Thread.currentThread().getContextClassLoader().getResource("").getPath() + ".." + File.separator + "..";
- String docStorePath = baasPath + File.separator + "model" +File.separator + "UI2" +File.separator + "69hsAdmin" +File.separator + "data" + File.separator + "attachmentSimple";
-
- String realFileName = request.getParameter("realFileName");
- String storeFileName = request.getParameter("storeFileName");
-
- File file = new File(docStorePath + File.separator +realFileName + File.separator + storeFileName);
- FileInputStream fis = new FileInputStream(file);
-
- response.setHeader("Cache-Control", "pre-check=0, post-check=0, max-age=0");
- String fileNameKey = "filename";
- response.addHeader("Content-Disposition", "inline; "+fileNameKey+"="" + storeFileName + """);
-
- OutputStream os = response.getOutputStream();
- byte[] buffer = new byte[BUFFER_SIZE];
- try {
- int read;
- while ((read = fis.read(buffer)) != -1) {
- os.write(buffer, 0, read);
- }
- } finally {
- fis.close();
- }
- return null;
- }
- }
复制代码 |
|