CONTROLLER:
package com.test.springmvcdemo.tang.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/user")
public class UserController {
@RequestMapping(path="/login")
public String Login(String userName, String userPwd){
try {
if(userName.equals("tangd") && userPwd.equals("123")){
/*返回成功视图*/
System.out.println("过来了!");
return "/show.jsp";
}else{
return "/login.jsp";
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return null;
}
}
访问页面:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>SPRING-MVC</title>
</head>
<body>
<form action = "user/login.action" method = "post">
用户名:<input type = "text" name = "userName"/><br/>
密 码:<input type = "password" name = "userPwd" />
<input type = "submit" value = "登录" />
</form>
</body>
</html>