0

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.

Cat
  • 41
  • 6

1 Answers1

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