需求:通过url访问WEB-INF下的静态.html文件下面是我的代码
@At("/html/?")
@Ok("re")
@Encoding(input="UTF-8",output="UTF-8")
public String LoadHtml(int Id,ServletContext context, HttpServletResponse resp) {
return "->:/WEB-INF/html/1.html";
}
代码可行 可以实现访问;但是stateCode 是304 技术负责人认为内部重定向影响性能要我用io流的方式响应下面是我的思路
@At("/html/?")
@Ok("re")
@Encoding(input="UTF-8",output="UTF-8")
public String LoadHtml(int Id,ServletContext context, HttpServletResponse resp) {
InputStream in = null;
try {
in = new BufferedInputStream(context.getResourceAsStream("/WEB-INF/html/1.html"));
byte[] buffer = new byte[10240];
int leng = 0;
while((leng = in.read(buffer)) != -1){
String str = new String(buffer,0,leng);
System.out.println(str);
resp.getWriter().write(str);
};
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return "";
}
然后就不会了 请Wendal 指点迷津