STRUTS2 Learning Notes (9)-result Configure global result sets _java

Source: Internet
Author: User

Result can be set globally, such as:

<struts> 
  <constant name= "Struts.devmode" value= "true"/> <package name= 
  "user" namespace= " User "extends=" struts-default > 
     
     
    <global-results> 
      <result name= "MainPage" >/main.jsp</ result> 
    </global-results> 
     
    <action name= "index" > 
      <result>/index.jsp</result > 
    </action> 
     
    <action name= "user" class= "com.bjsxt.struts2.user.action.UserAction" > 
      <result>/user_success.jsp</result> 
      <result name= "error" >/user_error.jsp</result> 
    </action>    
  </package> 
   
  <package name= "admin" namespace= "/admin" extends= "User" > 
    <action name= "admin" class= "com.bjsxt.struts2.user.action.AdminAction" > 
      <result>/ admin.jsp</result> 
    </action> 
  </package> 

which

<global-results> 
  <result name= "mainpage" >/main.jsp</result> 
</global-results>

Is the set of global result set, in this way, all the user package results as long as the return "MainPage", will jump to the main.jsp page, it uses a lot, the most common is the user fill in the URL error, jump to the homepage or error page. So how do you use a global result set under other packages?

As above the

<package name= "admin" namespace= "/admin" extends= "user" > 
  <action name= "admin" class= Com.bjsxt.struts2.user.action.AdminAction "> 
    <result>/admin.jsp</result> 
  </action> 

This is the inheritance relationship of the package, the admin package inherits from the user package, so he has all the attributes under the user bundle, which is very handy, and when we have a lot of public pages to display, we can write them into the parent package of these packages, and we'll put these public result into it, Other packages simply inherit this package.

The above is STRUTS2 use result to configure the entire content of the global results set, I hope to give you a reference, but also hope that we support the cloud habitat community.

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.