java 代码
1. package com.betop.probe.controller.study;
2.
3. import java.util.HashMap;
4. import java.util.Map;
5.
6. import javax.servlet.http.HttpServletRequest;
7. import javax.servlet.http.HttpServletResponse;
8.
9. import org.springframework.validation.BindException;
10. import org.springframework.web.bind.ServletRequestDataBinder;
11. import org.springframework.web.servlet.ModelAndView;
12. import org.springframework.web.servlet.mvc.AbstractCommandController;
13.
14. import com.betop.probe.domain.MasterUser;
15.
16. public class UserMultiActionController3 extends AbstractCommandController{
17.
18. public UserMultiActionController3(){
19. this.setCommandClass(MasterUser.class);
20. }
21.
22. public ModelAndView demo1(HttpServletRequest req, HttpServletResponse resp)throws Exception {
23.
24. Map model = new HashMap();
25. model.put("message", "这是MultiActioncontroller的第三种配置!");
26. return new ModelAndView("study/MultiActionControllerView3.vm", model);
27. }
28.
29. public ModelAndView demo2(HttpServletRequest req, HttpServletResponse resp)throws Exception{
30.
31.
32. MasterUser user = getCommand(req, resp);
33.
34. Map model = new HashMap();
35.
36. model.put("user", user);
37.
38. return new ModelAndView("study/result.vm", model);
39. //return super.handleRequest(req, resp);
40. }
41.
42. private MasterUser getCommand(HttpServletRequest req, HttpServletResponse resp) throws Exception{
43.
44. MasterUser command = (MasterUser)getCommand(req);
45. ServletRequestDataBinder binder = bindAndValidate(req, command);
46. BindException errors = new BindException(binder.getBindingResult());
47.
48. return command;
49. }
50.
51. @Override
52. protected ModelAndView handle(HttpServletRequest request,
53. HttpServletResponse response, Object command, BindException errors)
54. throws Exception {
55. // TODO Auto-generated method stub
56. return null;
57. }
58.
59. }
xml代码:
# <bean id="testMulti3" class="com.betop.probe.controller.study.UserMultiActionController3"/>
#
# <bean id="proxyController" class="org.springframework.web.servlet.mvc.multiaction.MultiActionController">
# <property name="methodNameResolver">
# <ref bean="paraMethodResolver"/>
# </property>
#
# <property name="delegate">
# <ref bean="testMulti3"/>
# </property>
# </bean>
#
# <bean id="SimpleUrlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
# <property name="mappings">
# <props>
# <prop key="/test/*.htm">proxyController</prop>
# </props>
# </property>
# </bean>
<bean id="paraMethodResolver" class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver">
<property name="paramName">
<value>method</value>
</property>
</bean>
1. package com.betop.probe.controller.study;
2.
3. import java.util.HashMap;
4. import java.util.Map;
5.
6. import javax.servlet.http.HttpServletRequest;
7. import javax.servlet.http.HttpServletResponse;
8.
9. import org.springframework.validation.BindException;
10. import org.springframework.web.bind.ServletRequestDataBinder;
11. import org.springframework.web.servlet.ModelAndView;
12. import org.springframework.web.servlet.mvc.AbstractCommandController;
13.
14. import com.betop.probe.domain.MasterUser;
15.
16. public class UserMultiActionController3 extends AbstractCommandController{
17.
18. public UserMultiActionController3(){
19. this.setCommandClass(MasterUser.class);
20. }
21.
22. public ModelAndView demo1(HttpServletRequest req, HttpServletResponse resp)throws Exception {
23.
24. Map model = new HashMap();
25. model.put("message", "这是MultiActioncontroller的第三种配置!");
26. return new ModelAndView("study/MultiActionControllerView3.vm", model);
27. }
28.
29. public ModelAndView demo2(HttpServletRequest req, HttpServletResponse resp)throws Exception{
30.
31.
32. MasterUser user = getCommand(req, resp);
33.
34. Map model = new HashMap();
35.
36. model.put("user", user);
37.
38. return new ModelAndView("study/result.vm", model);
39. //return super.handleRequest(req, resp);
40. }
41.
42. private MasterUser getCommand(HttpServletRequest req, HttpServletResponse resp) throws Exception{
43.
44. MasterUser command = (MasterUser)getCommand(req);
45. ServletRequestDataBinder binder = bindAndValidate(req, command);
46. BindException errors = new BindException(binder.getBindingResult());
47.
48. return command;
49. }
50.
51. @Override
52. protected ModelAndView handle(HttpServletRequest request,
53. HttpServletResponse response, Object command, BindException errors)
54. throws Exception {
55. // TODO Auto-generated method stub
56. return null;
57. }
58.
59. }
xml代码:
# <bean id="testMulti3" class="com.betop.probe.controller.study.UserMultiActionController3"/>
#
# <bean id="proxyController" class="org.springframework.web.servlet.mvc.multiaction.MultiActionController">
# <property name="methodNameResolver">
# <ref bean="paraMethodResolver"/>
# </property>
#
# <property name="delegate">
# <ref bean="testMulti3"/>
# </property>
# </bean>
#
# <bean id="SimpleUrlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
# <property name="mappings">
# <props>
# <prop key="/test/*.htm">proxyController</prop>
# </props>
# </property>
# </bean>
<bean id="paraMethodResolver" class="org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver">
<property name="paramName">
<value>method</value>
</property>
</bean>