- 论坛徽章:
- 0
|
本帖最后由 tong0245 于 2012-12-13 13:51 编辑
@RequestMapping("/resources")
public class ResourcesController {
@RequestMapping("/{path}")
public void home(@PathVariable("path") String path,
HttpServletRequest request,
HttpServletResponse response) throws FileNotFoundException, IOException {
FileReader read = null;
BufferedReader br = null;
try {
String fileName = request.getSession().getServletContext().getRealPath(
"/")
+ "WEB-INF/"+path;
read = new FileReader(fileName);
br = new BufferedReader(read);
String line = null;
while ((line = br.readLine()) != null) {
response.getWriter().write(line);
}
} finally {
if (br != null) {
br.close();
}
if (read != null) {
read.close();
}
}
}
}
|
|