@RequestMapping(value = "/start", method = RequestMethod.POST)
public String startpost1() {
return "redirect:name";
}
拦截器
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="control"></context:component-scan>
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/test/*" />
<bean class="intercepter.MyIntercepter" />
</mvc:interceptor>
</mvc:interceptors>
</beans>
public class MyIntercepter implements HandlerInterceptor{
//猪主要为了释放资源
@Override
public void afterCompletion(HttpServletRequest arg0,
HttpServletResponse arg1, Object arg2, Exception arg3)
throws Exception {
// TODO Auto-generated method stub
}
//控制器执行完,生成视图之前可以做的动作,向模型中加入公告成员
@Override
public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1,
Object arg2, ModelAndView arg3) throws Exception {
// TODO Auto-generated method stub
}
@Override
public boolean preHandle(HttpServletRequest arg0, HttpServletResponse arg1,
Object arg2) throws Exception {
// TODO Auto-generated method stub
return false;
}
}
@RequestMapping(value = "/start", method = RequestMethod.GET)
public String start(@Validated Data date,BindingResult result) {// @Validated 对date进行条件的验证,验证出错的结果放到result中
if(result.hasErrors()){
return "error";
}
return "start";
}
public class Data {
@NotEmpty
private String name;
private String password;
}