执行流程如下:
【步骤一】
创建一个MyFormController
欲执行则必须创建一个doSubmitAction方法。
且Post方式提交才会触发doSubmitAction方法,切记切记。
package com.myapps.web.controller; import org.springframework.web.servlet.mvc.SimpleFormController; import com.myapps.pojo.Person; public class MyFormController extends SimpleFormController { public MyFormController(){ this.setCommandClass(Person.class); this.setCommandName("person"); } @Override protected void doSubmitAction(Object command) throws Exception { Person p=(Person)command; System.out.println("我是MyFormController:"+p); } }
【步骤二】
在spring-mvc.xml中添加上相应的配置如下:
<!-- SimpleFormController --> <bean name="/myform.action" class="com.myapps.web.controller.MyFormController"> <property name="formView" value="formController"></property> <property name="successView" value="index"></property> </bean>
【步骤三】
在/WEB-INF/jsps/formController.jsp
<%@ 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> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Test FormController</title> </head> <body> <form action="${pageContext.request.contextPath }/myform.action" method="post"> <input type="hidden" name="id"> <table> <tr> <td>name:</td> <td><input type="text" name="name" /> </td> </tr> <tr> <td>age:</td> <td><input type="text" name="age" /> </td> </tr> <tr> <td></td> <td><input type="submit" value="提交表单" /> </td> </tr> </table> </form> </body> </html>
【步骤四】
在浏览器地址栏输入:
http://localhost:8080/springmvc/myform.action
控制台打印输出:
我是MyFormController:Person [name=luffy, age=17]
相关推荐
SpringMVC ---- HelloWorld ---- 代码 SpringMVC ---- HelloWorld ---- 代码 SpringMVC ---- HelloWorld ---- 代码 SpringMVC ---- HelloWorld ---- 代码 SpringMVC ---- HelloWorld ---- 代码 SpringMVC ---- Hello...
redis-service_pubsub.rar。 springMVC集成spring-data-redis实现发布订阅。
SpringMVC-Activiti5.16-Shiro-EasyUI,以前CSDN有的资源找不到了,新上传一个
SpringMVC------从HelloWorld开始
基于SpringMVC Mybatis Shiro Redis 的权限管理系统,该系统已经部署到线上,线上访问地址:http://shiro.itboy.net,登录账号:admin 密码:sojson,,详细教程参考sojson.com/shiro
SpringMVC-Mybatis-Shiro-redis-master..............
dubbo2.5-spring4-mybastis3.2-springmvc4-mongodb-redis, dubbo2.5-spring4-mybastis3.2-springmvc4-mongodb-redis整合
SpringMVC精品资源--ReactJS-Spring-Boot-Full-Stack-App
SpringMVC精品资源--SpringMVC+Mybatis 脚手架
SpringMVC精品资源--JAX-RS & SpringMVC supported maven buil
SpringMVC精品资源--JAX-RS & SpringMVC supported gradle bui
SSM完美整合Activiti工作流以及Shiro权限框架,初学者最实用的项目。
基于SpringMVC、Mybatis、Redis、Freemarker的Shiro管理Demo源码的升级版 相关详细配置说明请参看 --> http://www.sojson.com/shiro
springmvc-springioc-lib.rar springmvc-springioc-lib.rar
SpringMVC精品资源--教程源码-springboot部分SpringMVC常用的注解; SpringBoot
SpringMVC精品资源--基于springMVC实现的解决方案系统
SpringMVC精品资源--Java platform springmvc demo for work !
SpringMVC精品资源--Spring Security Core Brewery
SpringMVC精品资源--SpringMVC+Spring+MyBatis+Vue.js
SpringMVC精品资源--Spring、SpringMVC、MyBatis、Spring Boot案例