如何在WEB-INF文件夹中隐藏JSP文件? [英] How can I hide the JSP file in WEB-INF folder?
问题描述
例如,在一个简单的Java Web应用程序中,假设您有一个Servlet TestServlet.java.例如,在部署描述(web.xml)中,您可以将表示/testpage
的请求映射到TestServlet,以便在请求/testapplication/testpage
时,TestServlet可以处理该请求.例如,您可以编写"Hello World"并发送响应.
In a simple Java web application, for example imagine you have a servlet TestServlet.java. In deployment description ( web.xml ) you can for example map the request coming to say /testpage
to TestServlet so that when /testapplication/testpage
is requested TestServlet handles the request. And you can for example write "Hello World" and send the response.
在目录结构(已部署到Web服务器的应用程序)中,TestServlet.java将驻留在:
In directory structure ( the application that is deployed to the web server ), TestServlet.java will reside in:
webapps\testapplication\WEB-INF\classes\com\packagename\TestClass.java
,这意味着无法使用浏览器访问此文件. (就像输入URL一样)
which means there is no way to get to this file using the browser. ( Like entering a URL )
您还可以获取请求分派器,并将请求和响应对象转发到诸如.getRequestDispatcher("/test.jsp")
之类的JSP文件.但随后文件将进入
You can also get the request dispatcher and forward the request and response object to a JSP file like .getRequestDispatcher("/test.jsp")
. But then the file will be in
webapps\testapplication\test.jsp
,因此连接到http:\\ server.com \ test.jsp也将获得此文件.
so connecting to http:\\server.com\test.jsp will also get this file.
我想将文件隐藏在WEB-INF文件夹中,以便客户端无法访问它,除非提供了我提供的映射.
I want to hide the file in WEB-INF folder so it can not be reached by the client except the mapping I have provided.
执行此操作的适当方法是什么?
What is the appropriate way for doing this?
推荐答案
我想将文件隐藏在WEB-INF文件夹中,以便客户端无法访问该文件.
将jsp文件保留在WEB-INF
下-例如,(WEB-INF/jsp)
,以便默认情况下Web容器不允许客户端直接访问WEB-INF文件夹下的资源,但是RequestDispatcher
可以访问它. /p>
Keep your jsp files under WEB-INF
for example - (WEB-INF/jsp)
, so that by default Web Containers does not allow resources under WEB-INF folder to be accessed directly by clients, but the RequestDispatcher
can access it.
request.getRequestDispatcher("/WEB-INF/test.jsp").forward(request, response);
这篇关于如何在WEB-INF文件夹中隐藏JSP文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!