I want to implement one thing in my project, but it does not work. I have a jsp page with a list of students(allStudents.jsp), I want when the project starts so that the login page comes out and after such as the admin enters his login and password only when he could immediately go to the page where the list of students. But my project does not ask me to enter my login and password and immediately opens the page where the list of students is.

Authorization Controller


package adil.java.schoolmaven.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMap ping;
import org.springframework.web.bind.annotation.RequestMet hod;
import org.springframework.web.bind.annotation.RequestPar am;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class AuthorizationController{


@RequestMapping(value="/admin", method = RequestMethod.GET)
public ModelAndView adminPage() {

ModelAndView m = new ModelAndView();
m.addObject("title", "you successfully logged in");
m.addObject("message", "home");
m.setViewName("admin");

return m;

}


@RequestMapping(value = "/login", method = RequestMethod.POST)
public ModelAndView login(@RequestParam(value = "error", required = false) String error,
@RequestParam(value = "logout", required = false) String logout) {

ModelAndView m = new ModelAndView();
if (error != null) {
m.addObject("error", "Invalid login and password");
}

if (logout != null) {
m.addObject("msg", "Logget out");
}

m.setViewName("login");

return m;
}
}



Student Controller

package adil.java.schoolmaven.controller;

import java.io.File;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletContext;
import adil.java.schoolmaven.entity.Student;
import adil.java.schoolmaven.service.StudentService;
import java.nio.file.FileSystemException;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autow ired;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping ;
import org.springframework.web.bind.annotation.PathVariab le;
import org.springframework.web.bind.annotation.PostMappin g;
import org.springframework.web.bind.annotation.RequestMap ping;
import org.springframework.web.bind.annotation.RequestMet hod;
import org.springframework.web.bind.annotation.RequestPar am;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class StudentController {

@Autowired
private ServletContext servletContext;

// Constructor based Dependency Injection
private StudentService studentService;

public StudentController() {

}

@Autowired
public StudentController(StudentService studentService) {
this.studentService = studentService;
}




@RequestMapping(value = "/allStudents", method = {RequestMethod.GET, RequestMethod.POST})

public ModelAndView displayAllUser() {
System.out.println("User Page Requested : All Students");
ModelAndView mv = new ModelAndView();
List<Student> studentList = studentService.getAllStudents();
mv.addObject("studentList", studentList);
mv.setViewName("allStudents");
return mv;
}

@RequestMapping(value = "/addStudent", method = RequestMethod.GET)
public ModelAndView displayNewUserForm() {
ModelAndView mv = new ModelAndView("addStudent");
mv.addObject("headerMessage", "Add Student Details");
mv.addObject("student", new Student());
return mv;
}

@PostMapping(value = "/addStudent")
public String saveNewStudent(@RequestParam("name") @NonNull String name,
@RequestParam("surname") @NonNull String surname,
@RequestParam("avatar") MultipartFile file)
throws IOException {

Student student = new Student();
student.setSurname(surname);
student.setName(name);

if (file != null && !file.isEmpty()) {
student.setAvatar(studentService.saveAvatarImage(f ile).getName());
}

studentService.saveStudent(student);
return "redirect:/allStudents";
}

@GetMapping(value = "/editStudent/{id}")
public ModelAndView displayEditUserForm(@PathVariable Long id) {
ModelAndView mv = new ModelAndView("editStudent");
Student student = studentService.getStudentById(id);
mv.addObject("headerMessage", "Редактирование студента");
mv.addObject("student", student);
return mv;
}

@PostMapping(value = "/editStudent")
public String saveEditedUser(
@RequestParam("id") Long id,
@RequestParam("name") String name,
@RequestParam("surname") String surname,
@RequestParam("avatar") MultipartFile file) {

try {

studentService.updateStudent(name, surname, file, studentService.getStudentById(id));

} catch (FileSystemException ex) {
ex.printStackTrace();
} catch (IOException e) {
return "redirect:/error";
}

return "redirect:/allStudents";
}

@GetMapping(value = "/deleteStudent/{id}")
public ModelAndView deleteUserById(@PathVariable Long id) {
studentService.deleteStudentById(id);
ModelAndView mv = new ModelAndView("redirect:/allStudents");

return mv;

}

}