spring - Spring boot http request always handled by the same method
问题描述
I'm trying to perform the user login functionality in my spring boot application, but it seems that all the http requests are handled by the same method, means that they're redirected into the same URL.
Here is my login controller
package com.lyes.webmail.demo.controllers;
import com.lyes.webmail.demo.DAO.UserDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class LoginController {
@Autowired
UserDAO asi;
@RequestMapping(value = "/login", method = RequestMethod.GET)
public String login(){
System.out.println("i'm here"); return "login";
}
@RequestMapping(value = "/connection", method = RequestMethod.POST)
public String logMe(@RequestParam String email, @RequestParam String password){
if(asi.login(email,password)){
System.out.println("success");
return "home";
}else{
System.out.println("failure");
return "error";
}
}
}
my login form
<form id="login-form" class="form" action="/connection" method="POST">
<h3 class="text-center text-info">Login to lyes web mail</h3>
<div class="form-group">
<label for="username" class="text-info">Email:</label><br>
<input type="text" name="email" id="username" class="form-control">
</div>
<div class="form-group">
<label for="password" class="text-info">Password:</label><br>
<input type="text" name="password" id="password" class="form-control">
</div>
<div class="form-group">
<input type="submit" name="submit" class="btn btn-info btn-md" value="Login">
</div>
</form>
And the SecurityConfig
which extends the WebSecurityConfigurerAdapter
in order to render the login page as the welcome page.
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
System.out.println("lyes");
httpSecurity.authorizeRequests()
.anyRequest()
.authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll();
}
}
In the login controller method i've put a sysout to analyse the behaviour, and the message i'm here
is printed twice, the first time when the login page loads and the second time when i submit the form.
Any suggestions !??
解决方案
推荐阅读
- python - 更改 vlc media_player 进程名称
- php - PHP 将在一行中显示所有记录
- sql - 如何使用计数运算符获取表的子集
- gcc - arm-non-eabi-ld:参数列表太长
- jupyter-notebook - 如何以编程方式注释掉 Jupyter Notebook 中的代码单元?
- r - 在R中用插入符号实现K个最近邻居
- python - 创建 TF 数据集时无法解析 TFRecords
- javascript - 将 src img 渲染为 HTML
- node.js - Nodejs为Redis请求设置超时
- git - 如果我使用多个远程存储库(Github 和 BitBucket),其他合作者会知道吗?