SpringMVC (III)-Other knowledge

Source: Internet
Author: User

This blog shows how to redirect results in the Controller class. for exceptions in the SpringMVC framework, how to capture them in a unified manner is also the integration of S (SpringMVC) SH.

I. By default, the Framework redirects through forwarding. What if we want to redirect? You only need to pass the View parameter in the returned result object in the Controller class. The RedirectView object is the redirected View.

View view = new RedirectView ("http://www.ljh.com/index.jsp ");

Returnnew ModelAndView (view );

You can also write the path to the configuration file or the property configuration file. In this way, the constructor of the ModelAndView object returned by our controller class only needs to set a string parameter.

Returnnew ModelAndView ("index ");

Use the redirection view parser in the configuration file to redirect pages.

   
  
  
   
 

In this way, multiple view parsers may appear in a configuration file. How can we determine which one to use? We can set the priority by setting order, It should be noted that InternalResourceViewResolver has the lowest priority, and the order attribute value is greater than the value of other view Resolvers. This ensures that all mappings are not forgotten. And achieve what we want. This is a learning of forwarding and redirection. In fact, some new settings have the same principle as others. We can view more information, such as APIs and online materials.

Ii. Exception. Generally, an Exception occurs in the project. We will jump to the specified error page to prevent unfriendly page information from being exposed to users. This function is easy to configure in SpringMVC. Prepare our error page. Put the path of the error page in the property configuration file to read it, and then add it to the configuration file:

 
  
   
    
     
    
     
View
      
    
   
 
 
 
  
   
    
     
Error
    
   
  
 

Add the following in the property configuration file:

Error. class = org. springframework. web. servlet. view. RedirectView

Error. url = http://www.egov.com/error.jsp

In this way, when any exception occurs, it will jump to the error page we set in advance.

3. Finally, let's take a look at the integration of the S (SpringMVC) SH three framework. SpringMVC and Spring can be seamlessly integrated, so there is no need to say too much here, you only need to import and write the jar package and configuration file required by the framework. Read the previous article on the Internet and write it in detail: Build SpringMvc + Spring + Hibernate development framework.


All in all, for the MVC process framework, we will learn one way. The others are similar. Through horizontal comparison, we will learn the equivalent of our cross-plane programming. The frameworks at the data persistence layer compare and learn from each other, and the frameworks at the business layer compare and learn from each other, so that we can draw inferences from each other and understand more deeply. Of course, development in practice is more helpful to our understanding.


Related Article

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.