SpringMVC 使用Form标签库制作登录表单

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SpringMVC</title>
<link href="style/style.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript">

	function refreshVcode(){
		document.getElementById("vcode").src="images/vcode.jpg?r="+Math.random();
	}

</script>
</head>
<body>
										<!-- 对象要和表单绑定,把对象传递过来 -->
	 <form:form action="" method="post" commandName="form">
	 <tr>
	 	<td>登录名:</td>
	 	<td>
	 		<form:input path="loginName" />
	 	</td>
	 </tr>
	 <tr>
	 	<td>密码:</td>
	 	<td>
	 		<form:password path="password" />
	 	</td>
	 </tr>
	 <tr>
	 	<td></td>
	 	<td>
	 		<input type="submit" value="登陆"/>
	 	</td>
	 </tr>
	 
	 </form:form>
</body>
</html>
ublic class LoginController {
	//方法的返回值返回一个对象
	@ModelAttribute("form")
	public LoginForm getForm(){
		return new LoginForm();
	}
	
	//我发送请求要访问login.html页面
	
	@RequestMapping(value="login",method=RequestMethod.GET)
	public String showLogin(){
		
		return "login";
	}
原文地址:https://www.cnblogs.com/Angelinas/p/5637997.html