|

楼主 |
发表于 2018-8-28 23:02:45
|
显示全部楼层
java代码这样有没有问题请看看,
public class SRgbryz {
public static JSONObject getwpCount(JSONObject params, ActionContext context)
throws SQLException, NamingException {
String in = params.getString("abc");
System.out.println("-----------------");
System.out.println(in);
JSONObject ret = new JSONObject();
ret.put("count", 1000);
return ret;
}
public static JSONObject uploadPicfile(JSONObject params,
ActionContext context) throws SQLException, NamingException,
IOException {
System.out.println("uploadPicfile is running...");
String ownerID = params.getString("ownerID");
String storeFileName = params.getString("storeFileName");
String picData = params.getString("picData");
String baasPath = Thread.currentThread().getContextClassLoader().getResource("").getPath() + ".." + File.separator + "..";
String docStorePath = baasPath + File.separator + "model" + File.separator + "UI2" + File.separator + "jdjmbr" + File.separator + "gbr";
File docstoreDir = new File(docStorePath);
if (!(docstoreDir.exists() && docstoreDir.isDirectory())) {
docstoreDir.mkdirs();
}
String storePath = docStorePath + File.separator + ownerID;
File storeDir = new File(storePath);
if (!(storeDir.exists() && storeDir.isDirectory())) {
storeDir.mkdirs();
}
System.out.println("后台计算的baasPath的值:" + baasPath);
System.out.println("后台计算的docStorePath的值:" + docStorePath);
System.out.println("后台计算的storeDir的值:" + storeDir);
BASE64Decoder decoder = new BASE64Decoder();
try {
byte[] decodedBytes = decoder.decodeBuffer(picData);
String imgFile = storePath + File.separator + storeFileName;
FileOutputStream out = new FileOutputStream(imgFile);
out.write(decodedBytes);
out.close();
System.out.println("图片上传成功!");
} catch (Exception e) {
System.out.println("图片上传失败!");
e.printStackTrace();
}
return null;
}
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() + ".." + File.separator + ".." ;
String docStorePath = baasPath + File.separator + "model" + File.separator + "UI2" + File.separator + "jdjmbr" + File.separator+"gbr" ;
String ownerID = request.getParameter("ownerID");
String storeFileName = request.getParameter("storeFileName");
File file = new File(docStorePath + File.separator +ownerID + 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;
}
} |
|