我正在使用 servlet 和 jsp 开发一个 Web 应用程序。我有一个index.html
现在我需要避免从浏览器直接访问我的登录页面
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login App using Servlet and JSP</title>
</head>
<body bgcolor="pink">
<center>
<a href="Register.jsp">Register</a>
<a href="Login.jsp" >Login</a>
</center>
</body>
</html>
现在我想阻止从浏览器直接访问Login.jsp
http://localhost:9090/LoginAppWithServletsJSPJDBC/Login.jsp
通过谷歌搜索,我知道我需要使用 <security-constraint>
为此。
请帮助我。我怎样才能实现这一目标。
最佳答案
只需将Login.jsp
移至WEB-INF
下即可,外部无法直接访问。
只有应用程序可以在需要时使用 RequestDispatcher
访问它。
示例代码:
// put this logic anywhere in your application whenever needed to show Login.jsp
request.getRequestDispatcher("WEB-INF/Login.jsp").forward(request, response);
关于java - 如何保护我的jsp页面不被直接访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21807691/