I have created a simple login page which in turn redirects to the list of file contents. I do have three separate servlets. LoginServlet, LogoutServlet and FileUploadServlet. Where the Login and Logoutservlet redirects to the main page. But the FileUploadServlet will display the page with the two text fields along with a file upload. When the user type the url with the FileUploadServlet name directly the page loads without logging in. How to restrict accessing this. Please help me.
Asked
Active
Viewed 36 times
0
-
check this example [Login System in Servlet](https://www.studytonight.com/servlet/login-system-example-in-servlet.php) – ArpanKhandelwal Dec 27 '19 at 05:35
-
Is it the validate.java will do the validation? – Cat Dec 27 '19 at 05:56
-
Validation will be done by "Login" servlet using "Validate" class. – ArpanKhandelwal Dec 27 '19 at 06:09
-
When i try accessing the servlet page directly it will not let me to access? – Cat Dec 27 '19 at 06:23
1 Answers
0
You could use AuthenticationFilters
in web.xml
. Please add a filter and write a method to authenticate every request whether it is valid or not.
The session Attributes can be used for validation. Like, during login, the session attributes can be set if credentials are valid, and so when the next request is made, the session attributes can be sent along with the request, which can be used for authenticating it. If the request doesn't have that session attribute, you could just scrap that request.

Sandeep Kumar
- 2,397
- 5
- 30
- 37
-
Please tell me how will add the authentication filters in my web.xml file and do the authentication. I am new to servlet. So please help me – Cat Dec 27 '19 at 05:54
-
Please help me in how to write a method to authenticate every request whether it is valid or not. – Cat Dec 27 '19 at 06:34
-
Please refer to the solution already given in https://stackoverflow.com/questions/13274279/authentication-filter-and-servlet-for-login – Aravind mohan Dec 27 '19 at 11:22