2014-02-16 63 views
0

我在做一個使用servlet和jsps的web應用程序。我有一個index.html的如何保護我的jsp頁面免於直接訪問

現在我需要避免瀏覽器我的登錄頁面的直接訪問

<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 

通過Google搜索,我開始知道我需要爲此使用<security-constraint>

請幫我。我該怎麼做到這一點。

+0

您必須在一般閱讀更多關於安全性。我會建議使用春季和春季安全措施來強化安全性。詳細瞭解春季和春季的安全。 – RaviH

+0

你在使用任何其他框架嗎?彈簧?條紋?一些更純粹的骨骼servlets? – 2014-02-16 05:29:40

+0

@RaviH我正在做一個基本的登錄應用程序使用servlets和jsp.Now我正在尋找保護我的jsp從瀏覽器直接訪問。我現在不使用Spring。 – Gundamaiah

回答

3

只需移動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); 

請看看What is WEB-INF used for in a Java web application?