首页 > 代码库 > springMVC3学习(六)--SimpleFormController
springMVC3学习(六)--SimpleFormController
SimpleFormController提交表单流程如下:
login.jsp
<form action="login" method="post"> 用户名:<input type="text" name="username"/></br> 密码:<input type="password" name="password"/></br> <input type="submit" value=http://www.mamicode.com/"提交">>
springMVC.xml<!-- 处理器 --> <bean name="/login" class="com.itmyhome.Login"> <!-- 返回处理成功页面 success.jsp --> <property name="successView" value=http://www.mamicode.com/"success"/>>
UserModel.javapublic class UserModel { private String username; private String password; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } }
Login.javaimport org.springframework.web.servlet.mvc.SimpleFormController; public class Login extends SimpleFormController { public Login() { setCommandClass(UserModel.class);// 设置命令对象实现类 setCommandName("user");// 设置命令对象的名字 } //以下内容省略 /*protected Object formBackingObject(HttpServletRequest request) throws Exception { return null; } protected Map referenceData(HttpServletRequest request) throws Exception { return null; }*/ public void doSubmitAction(Object obj) throws Exception { UserModel user = (UserModel) obj; System.out.println(user); } }
success.jsp<body> 注册成功,欢迎: ${user.username }! </body>
测试:浏览器中输入:http://localhost:8080/spring_SimpleFormController/login.jsp 进入登录页面
注册成功页面:
源码下载:http://download.csdn.net/detail/itmyhome/7366879
欢迎加入JAVA技术交流群:74955800
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。