I would like to know if anyone has a solution for accessing website resources only through a servlet. I have all my resources under WEB-INF. In other words, I do not want users to have direct access to any of my resources.
You can use ServletContext#getResource()for this.
ServletContext#getResource()
URL resource = getServletContext().getResource("/WEB-INF/file.ext"); File file = new File(resource.getPath()); // ...
You can even use ServletContext#getResourceAsStream()to get InputStream:
ServletContext#getResourceAsStream()
InputStream
InputStream input = getServletContext().getResourceAsStream("/WEB-INF/file.ext"); // ...
As you can see in the examples, it ServletContextis available in inherited servlets GenericServlet#getServletContext().
ServletContext
GenericServlet#getServletContext()
, , - . . ? URL-. " "? ? , Filter .
Filter
JSP . , - ( MVC), JSP RequestDispatcher#forward(), ServletRequest#getRequestDispatcher().
RequestDispatcher#forward()
ServletRequest#getRequestDispatcher()
request.getRequestDispatcher("/WEB-INF/page.jsp").forward(request, response);
jsp . jsp -, :http://tomcat.apache.org/tomcat-5.5-doc/jasper-howto.html#Web%20Application%20Compilation
html/js/css - . , , .
Source: https://habr.com/ru/post/1744651/More articles:What is the safest way to delete data from mysql? (PHP / MySQL) - phpSyntax for RETURN clause in Mysql PDO - databaseRuby On Rails - XML-RPC - ruby-on-railsЭкземпляр метки центра внутри VGroup в Flex - alignmentProviding XML-RPC service from ruby on rails application? - ruby-on-railsНавигация по строкам курсора в SQLite (можете ли мы перемотать /reset курсор, например, вернуться к первой строке?) - pythonКак правильно преобразовать const char *, возвращаемый функцией, в const char ** в C? - cdropdownlist hierachy parameter filter - jqueryLucene: The fastest way to return phrase documentation? - pythonIs there any class in the .NET Framework to represent a container for storing objects? - multithreadingAll Articles