运行spring-boot应用程序后,JSP文件未显示<h2>

时间:2019-04-16 11:05:20

标签: html spring-boot jsp

在tomcat嵌入式服务器中运行该应用程序后,我被重定向到仅显示登录表单的登录页面。但是在login.jsp中,我有一个包含指向注册表单的链接的链接。导航到http://localhost:8080/login时看不到它。 我添加了http:// localhost:8080 / registration,但是我总是被重定向到/ login表单

控制器:

@Controller
public class UserController {
@Autowired
private UserService userService;

@Autowired
private ShopService shopService;

@Autowired
private SecurityService securityService;

@Autowired
private UserValidator userValidator;

@GetMapping("/registration")
public String registration(Model model) {
    model.addAttribute("userForm", new User());

    return "registration";
}

@PostMapping("/registration")
public String registration(@ModelAttribute("userForm") User userForm, BindingResult bindingResult) {
    userValidator.validate(userForm, bindingResult);

    if (bindingResult.hasErrors()) {
        return "registration";
    }

    userService.save(userForm);

    securityService.autoLogin(userForm.getUsername(), userForm.getPasswordConfirm());

    return "redirect:/welcome";
}

@GetMapping("/login")
public String login(Model model, String error, String logout) {
    if (error != null)
        model.addAttribute("error", "Your username and password is invalid.");

    if (logout != null)
        model.addAttribute("message", "You have been logged out successfully.");

    return "login";
}

@GetMapping({"/", "/welcome"})
public String welcome(Model model) {
    return "welcome";

}

登录JSP:

               登录

    <div class="form-group ${error != null ? 'has-error' : ''}">
        <span>${message}</span>
        <input name="username" type="text" class="form-control" placeholder="Username"
               autofocus="true"/>
        <input name="password" type="password" class="form-control" placeholder="Password"/>
        <span>${error}</span>
        <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>

        <button class="btn btn-lg btn-primary btn-block" type="submit">Log In</button>
        <h2 class=text-center><a href="www.google.com">www.google.com</a></h2>
        <h4 class="text-center"><a href="${contextPath}/registration">Create an account</a></h4>
        <h2 class=text-center><a href="www.google.com">www.google.com</a></h2>

    </div>
  </form>
</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="${contextPath}/resources/js/bootstrap.min.js"></script>

0 个答案:

没有答案