java servletFilter找不到文件

时间:2015-07-29 18:27:58

标签: java css servlet-filters

我有下一个结构的Java Web Application:

WEB-INF/
    lib/
    classes/
        contoller/
             MainServlet.class
             MainFilter. class
    web.xml
META-INF/
styles/
   default.css
enter.jsp
end.jsp

使用MainFilter,我尝试加载 default.css 文件并将其发送回浏览器。但我没有成功(((我的代码:

public void doFilter(ServletRequest req, ServletResponse resp,
            FilterChain chain) throws IOException, ServletException {
        String file = null;
        PrintWriter out = resp.getWriter();
        HttpServletRequest request = (HttpServletRequest ) req;
        String requestURI =  request.getRequestURI();
        BufferedReader in = null;

        String[] url= requestURI.split("\\/");
        for(String string: url) {
            if (string.contains("css")) {
                file = string;
            }
        }

if( file != null) {
            try {
                in = new BufferedReader(new FileReader(file));
//other irrelevant code
            } catch (FileNotFoundException e) {
                System.out.println("Was not able to open " + file);
            }
      }
}

我尝试将" default.css" 作为文件变量," styles / default.css" 。我试图将 default.css 与jsp文件放在一起。我的MainFilter继续生成 FileNotFound异常(((你能帮忙吗?我应该放置什么样的路径,以便我的过滤器可以找到css文件?

0 个答案:

没有答案