Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
488 views
in Technique[技术] by (71.8m points)

java - global results across different packages defined in struts configuration file

I would like to create a global-results across different packages which are under different namespaces. Can I know the conventions that required to follow in struts config file?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Define global result in the package that other packages extend. For example

<package name="default" extends="struts-default">
  ...
  <global-results>
    <result name="error">/pages/error_page.jsp</result>
  </global-results>
  ...
</package>

This result could be used across actions that forward to error page and as exception handling result.

If you are using conventions plugin with annotations you could define @Results annotation on the class that has the parent package other packages extend. For example

@Results({
  @Result(name = ERROR, location = "/pages/error_page.jsp"),
})

The parent package is annotated with @ParentPackage annotation. It could be placed on the class but better place it on the package. For example

package-info.java:

@ParentPackage("default")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...