|
1、如何在页面中显示活下载服务器中非项目路径下的图片和文件,比如显示D:\images\aa.jpg,我在java开发中常用下面这种方式,不知道X5中是如何实现的:
@RequestMapping(value = "/download/{filepath}/{filename}")
public void download(HttpServletRequest request, HttpServletResponse response,
@PathVariable(value = "filepath") String filepath, @PathVariable(value = "filename") String filename) {
response.setContentType("application/octet-stream;charset=UTF-8");
String resourcepath = env.getProperty("resourcepath");
String pathname = resourcepath + filepath + File.separator + filename;
File file = new File(pathname);
if (file.isDirectory()) {
return;
}
if (file.exists()) {
try (FileInputStream in = new FileInputStream(file);
OutputStream outputStream = new BufferedOutputStream(response.getOutputStream());) {
int i = in.available();
byte[] data = new byte;
in.read(data);
// 写图片
outputStream.write(data);
outputStream.flush();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
2、在X5中如何单独写一个servlet,例如我需要用一个网页插件实现文件上传功能,代码如下:
@RequestMapping("/fileUpload")
public String fileUpload(@RequestParam(name = "filedata", required = false) MultipartFile filedata,
HttpServletRequest request) {
String resourcepath = env.getProperty("resourcepath");
String fileName = filedata.getOriginalFilename();
String dirpath = resourcepath + File.separator + "video/";
if (fileName.toLowerCase().endsWith(".jpg")) {
dirpath = resourcepath + File.separator + "images/";
}
File dir = new File(dirpath);
if (dir.exists() || dir.mkdir() || dir.mkdirs()) {
String filePath = dirpath + fileName;
try (FileOutputStream out = new FileOutputStream(filePath)) {
out.write(filedata.getBytes());
out.flush();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
return fileName;
}
3、比如我模型数据中的fId为030B219A65474C76A2DE43A8F2CB37F7,如何让我在页面中img标签的src为030B219A65474C76A2DE43A8F2CB37F7.jpg,其文件名前缀与fId一致,还有a标签的href属性也实现类似功能。
4、input标签,如何只设置readonly属性而不设置disabled?我现在只要设置了readonly,页面的disabled也自动变成true了,提交时候就没有数据了。
|
|