后台处理方法
@RequestMapping(value="/doLogin", method=RequestMethod.POST)
public ModelAndView doLogin(HttpSession session){
logger.info("user login.");
session.setAttribute("USER", "admin");
//return "superMain.html";
return new ModelAndView(new InternalResourceView("/view/superMain.html"));
}
mvc配置
<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="order" value="1"/>
<property name="contentNegotiationManager" ref="contentNegotiationManager"/>
<property name="viewResolvers">
<list>
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/view/" />
</bean>
</list>
</property>
<property name="defaultViews">
<list>
<bean class="org.springframework.web.servlet.view.json.MappingJackson2JsonView"/>
</list>
</property>
</bean>
页面html代码
<form action="doLogin" method="post">
<div class="form-group">
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-user"></i></div>
<input class="form-control" placeholder="Username" type="text" />
</div>
</div>
<div class="form-group">
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-asterisk"></i></div>
<input class="form-control" placeholder="Password" type="password" />
</div>
</div>
<div class="row">
<div class="col-xs-4">
<div class="form-group text-right">
<button class="btn btn-success text-uppercase" type="submit">Sign In</button>
</div>
</div>
</div>
</form>
错误信息
11:54:35.105 [http-apr-8080-exec-3] DEBUG o.s.web.servlet.DispatcherServlet - DispatcherServlet with name 'springMvc' processing POST request for [/cbos-web-1.0/doLogin]
11:54:35.118 [http-apr-8080-exec-3] DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Looking up handler method for path /doLogin
11:54:35.133 [http-apr-8080-exec-3] DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Returning handler method [public org.springframework.web.servlet.ModelAndView com.gtstar.cbos.web.controller.LoginController.doLogin(javax.servlet.http.HttpSession)]
11:54:35.137 [http-apr-8080-exec-3] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'loginController'
- user login. 11:54:35.181 [http-apr-8080-exec-3] DEBUG o.s.web.servlet.DispatcherServlet - Rendering view [org.springframework.web.servlet.view.InternalResourceView: unnamed; URL [/view/superMain.html]] in DispatcherServlet with name 'springMvc' 11:54:35.183 [http-apr-8080-exec-3] DEBUG o.s.w.s.view.InternalResourceView - Forwarding to resource [/view/superMain.html] in InternalResourceView 'null' 11:54:35.183 [http-apr-8080-exec-3] DEBUG o.s.web.servlet.DispatcherServlet - DispatcherServlet with name 'springMvc' processing POST request for [/cbos-web-1.0/view/superMain.html] 11:54:35.189 [http-apr-8080-exec-3] DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Looking up handler method for path /view/superMain.html 11:54:35.194 [http-apr-8080-exec-3] DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Did not find handler method for [/view/superMain.html] 11:54:35.209 [http-apr-8080-exec-3] DEBUG o.s.w.s.h.SimpleUrlHandlerMapping - Matching patterns for request [/view/superMain.html] are [/view/**] 11:54:35.226 [http-apr-8080-exec-3] DEBUG o.s.w.s.h.SimpleUrlHandlerMapping - URI Template variables for request [/view/superMain.html] are {} 11:54:35.238 [http-apr-8080-exec-3] DEBUG o.s.w.s.h.SimpleUrlHandlerMapping - Mapping [/view/superMain.html] to HandlerExecutionChain with handler [ResourceHttpRequestHandler [locations=[ServletContext resource [/WEB-INF/view/]], resolvers=[org.springframework.web.servlet.resource.PathResourceResolver@783c52dc]]] and 1 interceptor 11:54:35.245 [http-apr-8080-exec-3] DEBUG o.s.w.s.m.a.ResponseStatusExceptionResolver - Resolving exception from handler [ResourceHttpRequestHandler [locations=[ServletContext resource [/WEB-INF/view/]], resolvers=[org.springframework.web.servlet.resource.PathResourceResolver@783c52dc]]]: org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported 11:54:35.250 [http-apr-8080-exec-3] DEBUG o.s.w.s.m.s.DefaultHandlerExceptionResolver - Resolving exception from handler [ResourceHttpRequestHandler [locations=[ServletContext resource [/WEB-INF/view/]], resolvers=[org.springframework.web.servlet.resource.PathResourceResolver@783c52dc]]]: org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported 11:54:35.257 [http-apr-8080-exec-3] WARN o.s.web.servlet.PageNotFound - Request method 'POST' not supported 11:54:35.275 [http-apr-8080-exec-3] WARN o.s.w.s.m.s.DefaultHandlerExceptionResolver - Handler execution resulted in exception: Request method 'POST' not supported 11:54:35.282 [http-apr-8080-exec-3] DEBUG o.s.web.servlet.DispatcherServlet - Null ModelAndView returned to DispatcherServlet with name 'springMvc': assuming HandlerAdapter completed request handling 11:54:35.316 [http-apr-8080-exec-3] DEBUG o.s.web.servlet.DispatcherServlet - Successfully completed request 11:54:35.317 [http-apr-8080-exec-3] DEBUG o.s.web.servlet.DispatcherServlet - Successfully completed request
望大师指导!!