发表于: 2020-07-24 22:35:13

1 1314


登录

配置

<!--配置拦截器-->
<mvc:interceptors>
   <mvc:interceptor>
       <mvc:mapping path="/u/*"/>
       <!--<mvc:exclude-mapping path=""/>-->
       <!--配置拦截器对象-->
       <bean "com.jnshu.Interceptor.MyInterceptor1"/>
   </mvc:interceptor>
</mvc:interceptors>
@Controller
public class AccountController {
private static final Logger logger = LogManager.getLogger(AccountController.class)
@Autowired
private AccountService accountService;

  
@RequestMapping(value = "toregister")
public String toregister(){
return "register";
   }



@RequestMapping(value = "register",method = RequestMethod.POST)
public String register(Account account,Model model){
account.setCreateat(1L);
       account.setCreateby("管理员");
       account.setUpdateat(1L);
       account.setUpdateby("管理员");
       accountService.insert(account);
       model.addAttribute("msg","注册成功");
       return "login";
   }


@RequestMapping(value = "tologin")
public String tologin(){
return "login";
   }



@RequestMapping(value = "login")
public String login(String username, String password, Model model){
Account account = new Account();
       account.setUsername(username);
       account.setPassword(password);
       if(accountService.select(account) != null){
model.addAttribute("username",username);
           return "index";
       }else{
model.addAttribute("error","账号密码错误");
           return "login";
       }
}
}
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
   <title>登录页面</title>
</head>
<body>
<form action="login" method="post">
   用户名:<input type="text" name="username"/><br>
   密码:<input type="text" name="password"/><br>
   <input type="submit" value="登录"/>
</form><a href="/task4/toregister">注册</a>
${error}${msg}
</body>
</html>

注册页面register.jsp:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
   <title>注册页面</title>
</head>
<body>
<form action="register" method="post">
   账户名:<input type="text" name="username"/><br>
   密码:<input type="text" name="password"/><br>
   <input type="submit" value="注册"/>
</form>
</body>
</html>

今日问题暂无


返回列表 返回列表
评论

    分享到