I am trying to load this specific JSP /url. But when it executes I get the following error.
This localhost page can’t be foundNo webpage was found for the web address: http://localhost:8181/home
HTTP ERROR 404
This is my Security Config
.permitAll()
.and().formLogin()
// to show the page where we enter login credentials
.loginPage("/login")
// to process authentication: /login handler method implemented by Spring Security
.loginProcessingUrl("/mylogin")
// where to go after successful login
.defaultSuccessUrl("/success", true)
// to show an error page if the authentication failed
.failureUrl("/login?Error=True")
// everyone can access these requests
.permitAll()
So when it is successful it goes to the url "/success". This is the following RequestMapping
@RequestMapping(value = "/success", method = RequestMethod.GET)
public String successLogin(Principal p) {
System.out.println("Shalom56765");
Volunteer user = volRepo.findByEmail(p.getName());
if (user.getKind().equals(UserKind.Admin)) {
return "/admin";
}
if (user.getKind().equals(UserKind.user)) {
System.out.println("user is a user");
return "redirect:/home";
}
return "login";
}}
And the mapping for "/home"
@RequestMapping("/home")
public String login(Model model, @RequestParam String email) {
model.addAttribute("volunteer", vrRepo.findAll());
model.addAttribute("user_email", email);
return "Homepage";
}
But the error I am getting is that it can't find "/home" what am I to do is anyone seeing a simple error that I cannot see. Thanks Guys. Jeff
Main Controller
@Controller
public class MainController {
@Autowired
private VolunteerRepository volrepo;
@RequestMapping("/")
public String start() {
return "start";
}
@RequestMapping("/sign_up")
public String signup() {
return "sign_up";
}
@RequestMapping("/admin")
public String dashboard( Model model, BindingResult result) {
System.out.println("IM GETTING CLICKED");
if(result.hasErrors()) {
}
else {
model.addAttribute("vols", volrepo.findAll());
return "admin";
}
return "/";}
}
Authentication Controller
@Controller
public class AuthenticationController {
@Autowired
private VolunteerRepository volRepo;
@Autowired
private AdminRepository adRepo;
@RequestMapping("/login")
public String login() {
return "login";
}
@RequestMapping(value = "/success", method = RequestMethod.GET)
public String successLogin(Principal p) {
Volunteer user = volRepo.findByEmail(p.getName());
Admin user2 = adRepo.findOne(p.getName());
System.out.println(user2.getUsername());
if (user2.getKind().equals(UserKind.Admin)) {
return "/admin";
}
if (user.getKind().equals(UserKind.user)) {
System.out.println("user is a user");
return "redirect:/home";
}
return "login";
}}
Volunteer Controller
@Controller
public class VolunterController {
@Autowired
private VolunteerRepository vrRepo;
@Autowired
private PasswordEncoder pe;
ArrayList<String> emails = new ArrayList<String>();
//Add new results
@RequestMapping(value = "/newUser",method = {RequestMethod.POST , RequestMethod.GET})
public String newResults(@Valid @ModelAttribute Volunteer vol, BindingResult result, Model model) {
if (result.hasErrors()) {
return "sign_up";
}
else {
String pass = vol.getPassword();
String crypt = pe.encode(pass);
vol.setPassword(crypt);
vol.setKind(UserKind.user);
vrRepo.save(vol);
return "Submit";
}}
@RequestMapping("/home")
public String login(Model model, @RequestParam String email) {
//model.addAttribute("volunteer", vrRepo.findAll());
// model.addAttribute("user_email", email);
return "Homepage";
}
//Add vaccine info
@RequestMapping(value = "/newInfo", method=RequestMethod.POST)
public String addVac(@Valid @ModelAttribute Volunteer vol, BindingResult result, Model model) {
//add extra fields
float dose = vol.getDose();
String group = vol.getVac_group();
String email = vol.getEmail();
System.out.println(dose +" " + group + " " + email);
List<Volunteer> vols = (List<Volunteer>) vrRepo.findAll();
for(int i=0;i<vols.size();i++){
String dbEmail = vols.get(i).getEmail();
System.out.println("Checking if Email " + email + " equals " + dbEmail);
if(dbEmail.equals(email)) {
System.out.println("MATCH");
Volunteer volUP = vrRepo.findByEmail(dbEmail);
volUP.setDose(dose);
volUP.setVac_group(group);
vrRepo.save(volUP);
System.out.println("User details are updated!");
break;
}
}
return "start";
}
//Add Positive Case
@RequestMapping(value = "/positive/{email}", method=RequestMethod.POST)
public String addPos(@ModelAttribute Volunteer vol, @PathVariable String email) {
System.out.println(email);
List<Volunteer> vols = (List<Volunteer>) vrRepo.findAll();
System.out.println(vols.size());
for(int i=0;i<vols.size();i++){
String dbEmail = vols.get(i).getEmail();
System.out.println("Checking if Email " + email + " equals " + dbEmail);
// if(dbEmail.equals(email)) {
System.out.println("MATCH");
Volunteer volUP = vrRepo.findByEmail(dbEmail);
volUP.setInfected("Positive");
vrRepo.save(volUP);
System.out.println("User details are updated!");
break;
// }
}
return "/";
}
@GetMapping(value= "/vaccine/all_result")
public String all(Model model) {
model.addAttribute(vrRepo.findAll());
return "all_vaccine";
}
@RequestMapping(value = "/sucess", method = RequestMethod.GET)
public String successLogin(Principal p) {
Volunteer user = vrRepo.findByEmail(p.getName());
if (user.getKind().equals(UserKind.user)) {
return "redirect:/home";
}
else
return "redirect:/userlogin";
}
@RequestMapping(value = "/login?error=true", method = RequestMethod.GET)
public String invalidLogin(Model model) {
model.addAttribute("error", true);
return "userlogin";
}
}