[Turn]spring MVC Annotation Method Implement Wizard-style jump page

Source: Internet
Author: User

Because the project needs to use the wizard-style jump page effect, this project is implemented with spring MVC, just beginning to think of Spring Webflow, but webflow too cumbersome, for we are not very complex jump as if there is a kind of "kill Chicken Yan with sledgehammer" feeling, So on-line search to see if there is a similar solution, the online answer is generally called you inherit Abstractwizardformcontoller this class to achieve, but for spring mvc3.0.x This class will no longer be used, instead recommend the use of annotations to implement, so refer to the official document, annotated way to implement the wizard-style page.

The following is a code example:

[Java] @Controller
@RequestMapping ("/wizard.htm")
Variables that need to be saved in the session
@SessionAttributes ("Bean")
public class testwizardcontroller{

@Resource (name = "Beanservice")
Private Beanservice Beanservice;

@RequestMapping
Public String Step1 (final Modelmap modelmap) {
Modelmap.addattribute ("Bean", New Bean ());
return "Step1";
}

@RequestMapping (params = "_step=2")
Public String Step2 (final @ModelAttribute ("bean") bean bean,
Final Errors Errors) {
return "Step2";
}

@RequestMapping (params = "_step=3")
Public String step3 (final @ModelAttribute ("bean") bean bean,
Final Errors Errors) {
return "Step3";
}

@RequestMapping (params = "_finish")
Public String Processfinish (@ModelAttribute ("bean") bean bean,
Final Errors Errors,
Final Modelmap Modelmap,
Final Sessionstatus status) {

Beanservice.add (Bean);
Status.setcomplete ();
Return "Success";
}

@RequestMapping (params = "_cancel")
Public String Processcancel (final httpservletrequest request,
Final HttpServletResponse response,
Final Sessionstatus status) {
Status.setcomplete ();
Return "Cancel";
}

}

One of the most important things about www.2cto.com is @sessionattributes, which defines a variable within the session range that can be persisted when a different page jumps.

Enter the Step1 method the first time you visit http:/www./example.com/wizard.htm, and then add the corresponding parameters after the form action that you submitted, such as:

Step1 page <form action= "http:/www./example.com/wizard.htm?_step=2" >

Step2 page <form action= "http:/www./example.com/wizard.htm?_step=3" >

Step3 page <form action= "Http:/www./example.com/wizard.htm?_finish" >

[Turn]spring MVC Annotation Method Implement Wizard-style jump page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.