Use spring MVC annotations to redirect pages

Source: Internet
Author: User

Because the project needs to use the Wizard Page jump effect, this project is implemented with spring MVC. At first, we thought of using spring webflow, but webflow is too cumbersome, for our not very complex jump, we seem to have the feeling of "getting rid of your teeth". So we searched online to see if there were any similar solutions, the answer on the internet is generally to ask you to inherit the abstractwizardformcontoller class for implementation, but for spring mvc3.0.x this class will not be used, instead we recommend using annotations for implementation, so refer to the official documentation, the Wizard Page is implemented by annotation.

Below isCodeExample:

@ Controller @ requestmapping ("/wizard.htm") // The variable to be saved in the session @ sessionattributes ("Bean") public class testwizardcontroller {@ Resource (name = "beanservice ") private beanservice; @ requestmapping Public String Step1 (final modelmap) {modelmap. addattribute ("Bean", new bean (); Return "Step1" ;}@ requestmapping (Params = "_ step = 2 ") public String step2 (final @ modelattribute ("Bean") bean, final errors) {return "step2" ;}@ requestmapping (Params = "_ step = 3 ") public String Step3 (final @ modelattribute ("Bean") bean, final errors) {return "Step3" ;}@ requestmapping (Params = "_ finish ") public String processfinish (@ modelattribute ("Bean") bean, final errors, final 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 ";}}

The annotation @ sessionattributes is the most effective one. It defines a variable within the session range, which can be maintained during different page jumps.

When you access http:/www./example.com/wizard.htmfor the first time, go to step 1, and add the corresponding response to the table ticket action2. for example:

Step 1 page <form action = "http:/www./example.com/wizard.htm? _ Step = 2 ">

Step 2 page <form action = "http:/www./example.com/wizard.htm? _ Step = 3 ">

Step 3 page <form action = "http:/www./example.com/wizard.htm? _ Finish ">

 

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.