I have Java Web Application with next structure:
WEB-INF/
lib/
classes/
contoller/
MainServlet.class
MainFilter. class
web.xml
META-INF/
styles/
default.css
enter.jsp
end.jsp
Using MainFilter, I tried to load default.css file and send it back to browser. But I was unsuccessful((( My code:
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);
}
}
}
I tried "default.css" as file variable, "styles/default.css". I tried to put default.css with jsp files. My MainFilter continues generating FileNotFound exception((( Can you help? What pelative path I should put so my filter could find css file?