我正在尝试加载这个特定的jsp/url。但当它执行时,我得到以下错误。
找不到此本地主机页找不到网址的网页:http://localhost:8181/home http错误404
这是我的安全配置
.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()
因此,当它成功时,它会转到url“/success”。以下是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";
}}
以及“/家”的Map
@RequestMapping("/home")
public String login(Model model, @RequestParam String email) {
model.addAttribute("volunteer", vrRepo.findAll());
model.addAttribute("user_email", email);
return "Homepage";
}
但我得到的错误是,它找不到“/家”,我要做的是任何人看到一个简单的错误,我看不见。谢谢你们。杰夫
主控制器
@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 "/";}
}
身份验证控制器
@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";
}}
志愿者管制员
@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";
}
}
1条答案
按热度按时间t5fffqht1#
考虑把它改成这样
我假设您希望它是一个post,它接受model对象的json等价性和电子邮件的可选路径参数