67,512
社区成员
发帖
与我相关
我的任务
分享
// 访问js文件的操作
private void jsAction(String url, HttpServletRequest request, HttpServletResponse response) throws Exception {
String fileUri = url.substring(0, url.lastIndexOf("."));
InputStream input = this.getClass().getResourceAsStream(fileUri);
if (null == input) {
throw new FrameworkException("找不到[" + fileUri + "]这个js文件");
}
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
PrintWriter out = response.getWriter();
response.setContentType("text/javascript;charset=UTF-8");
String line = null;
while ((line = reader.readLine()) != null) {
if (line.indexOf("getV(\"hdfPath\")") != -1) {
line = line.replace("getV(\"hdfPath\")", "\"" + request.getContextPath() + "\"");
}
if (line.indexOf("getV('hdfPath')") != -1) {
line = line.replace("getV('hdfPath')", "'" + request.getContextPath() + "'");
}
if (line.indexOf("${suffix}") != -1) {
line = line.replace("${suffix}", url.substring(url.lastIndexOf(".") + 1, url.length()));
}
out.println(line);
}
reader.close();
out.close();
out.flush();
input.close();
}
// 访问图片或flash的操作
private void imgAction(String url, HttpServletResponse response) throws Exception {
InputStream input =null;
OutputStream output = null;
try {
String fileUri = url.substring(0, url.lastIndexOf("."));
input = this.getClass().getResourceAsStream(fileUri);
if (null == input) {
throw new FrameworkException("找不到[" + fileUri + "]这个图片或flash");
}
output = response.getOutputStream();
byte[] buffer = new byte[1024];
int i = 0;
while ((i = input.read(buffer)) != -1) {
output.write(buffer, 0, i);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if(null !=output) {
//output.flush();
output.close();
}
if(null !=input) {
input.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}