登录后出现Request method ‘POST’ not supported
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-XK2oKEMy-1620441587738)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-ima
ges\image-20210508094848193.png)]
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-DxnI3kH9-1620441587761)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20210508094745498.png)]
日志
[org.springframework.web.servlet.DispatcherServlet]-GET "/ssmOne-controller/pages/all-admin-login.html", parameters={}
[org.springframework.web.servlet.handler.SimpleUrlHandlerMapping]-Mapped to ResourceHttpRequestHandler ["/pages/"]
[org.springframework.web.servlet.DispatcherServlet]-Completed 200 OK
[org.springframework.web.servlet.DispatcherServlet]-POST "/ssmOne-controller/all-admin-index", parameters={masked}
[org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping]-Mapped to com.lpit.controller.LoginController#judgeLogin(S_user, HttpSession)
S_user check(S_user user)======
[org.mybatis.spring.SqlSessionUtils]-Creating a new SqlSession
[org.mybatis.spring.SqlSessionUtils]-SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1b1921b0] was not registered for synchronization because synchronization is not active
[org.springframework.jdbc.datasource.DataSourceUtils]-Fetching JDBC Connection from DataSource
[com.alibaba.druid.pool.DruidDataSource]-{dataSource-1} inited
[org.mybatis.spring.transaction.SpringManagedTransaction]-JDBC Connection [oracle.jdbc.driver.T4CConnection@6f0d9c84] will not be managed by Spring
[com.lpit.dao.ILoginDao.getUserByEmailAndPassword]-==> Preparing: select * from s_user where email=? and userPassword=?
[com.lpit.dao.ILoginDao.getUserByEmailAndPassword]-==> Parameters: 233@163.com(String), 123456(String)
[com.lpit.dao.ILoginDao.getUserByEmailAndPassword]-<== Total: 1
[org.mybatis.spring.SqlSessionUtils]-Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1b1921b0]
-------------------S_user(userId=0, email=233@163.com, username=admin, userPassword=123456, phoneNum=123456789, status=1)
S_user check(S_user user)------>userByEmailAndPassword.getEmail():
success
[org.springframework.web.servlet.view.JstlView]-View name 'all-admin-index', model {s_user=S_user(userId=null, email=233@163.com, username=null, userPassword=123456, phoneNum=null, status=null), org.springframework.validation.BindingResult.s_user=org.springframework.validation.BeanPropertyBindingResult: 0 errors}
[org.springframework.web.servlet.view.JstlView]-Forwarding to [/pages/all-admin-index.html]
[org.springframework.web.servlet.DispatcherServlet]-"FORWARD" dispatch for POST "/ssmOne-controller/pages/all-admin-index.html", parameters={masked}
[org.springframework.web.servlet.handler.SimpleUrlHandlerMapping]-Mapped to ResourceHttpRequestHandler ["/pages/"]
[org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver]-Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported]
[org.springframework.web.servlet.DispatcherServlet]-Exiting from "FORWARD" dispatch, status 405
[org.springframework.web.servlet.DispatcherServlet]-Completed 405 METHOD_NOT_ALLOWED
login.html
<form action="/ssmOne-controller/all-admin-index" method="post" enctype="application/x-www-form-urlencoded">
<div class="form-group has-feedback">
<input type="email" class="form-control" placeholder="Email" name="email">
<span class="glyphicon glyphicon-envelope form-control-feedback"></span>
</div>
<div class="form-group has-feedback">
<input type="password" class="form-control" placeholder="密码" name="userPassword">
<span class="glyphicon glyphicon-lock form-control-feedback"></span>
</div>
<div class="row">
<div class="col-xs-8">
<div class="checkbox icheck">
<label><input type="checkbox"> 记住 下次自动登录</label>
</div>
</div>
<!-- /.col -->
<div class="col-xs-4">
<button type="submit" class="btn btn-primary btn-block btn-flat">登录</button>
</div>
<!-- /.col -->
</div>
</form>
LoninController类
@Controller
public class LoginController{
@Autowired
ILoginService loginService;
@RequestMapping(path = "/all-admin-index")
public String judgeLogin(S_user user, HttpSession session) {
S_user check = loginService.check(user);
if(check != null){
session.setAttribute("userTwo",check);
System.out.println("success");
//return "redirect:/pages/all-admin-index.html";
return "all-admin-index";
}else {
System.out.println("shibai");
//return "forward:/pages/all-admin-login.html";
return "all-admin-login";
}
}
}
spring-mvc.xml
<import resource="applicationContext.xml"/>
<!--开启注解扫描-->
<context:component-scan base-package="com.lpit.controller"/>
<!--视图解析器对象-->
<bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/pages/"/>
<property name="suffix" value=".html"/>
</bean>
<!--开启SpringMVC框架的注解支持-->
<mvc:annotation-driven/>
<!--前段控制器,哪些静态资源不拦截-->
<mvc:default-servlet-handler/>
<mvc:resources mapping="/css/**" location="/css/"/>
<mvc:resources mapping="/img/**" location="/img/"/>
<mvc:resources mapping="/pages/**" location="/pages/"/>
<mvc:resources mapping="/plugins/**" location="/plugins/"/>
问题原因:
<!--我的理解是这里的pages让spring管理了-->
<property name="prefix" value="/pages/"/>
<!--这里又配置它不让spring管理-->
<mvc:resources mapping="/pages/**" location="/pages/"/>