作业九
程序员文章站
2022-07-12 23:35:24
...
controller层
//登录
@RequestMapping(value="/login.html",method=RequestMethod.POST)
public String dologin(String username,String password,HttpServletRequest request,HttpSession session){
//调用业务逻辑层
User user=us.findUser(username, password);
if(user==null){
/*request.setAttribute("errors", "用户名密码不正确");
return "login";*/
throw new RuntimeException("用户名密码不正确....");
}else{
System.out.println("控制器user用户的值:"+user.getUserName()+user.getUserPassword());
session.setAttribute("currentUser", user);
//return "main";
return "redirect:/user/main.html";
}
}
//定义跳转到主页面的处理器
@RequestMapping(value="/main.html")
public String doMain(){
return "main";
}
// 退出登录
@RequestMapping(value = "logout.html")
public String logout() {
return "redirect:/outStaff/login.html";
}
springmvc-servlet.xml
<!-- 配置全局异常-->
<bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">
<property name="exceptionMappings">
<props>
<prop key="java.lang.RuntimeException">
error
</prop>
</props>
</property>
</bean>