Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

java - How to define a global page when requested page or method is not found?

I know how to fine a global error redirect page in our defined package when exception encountered that just by adding the following configuration in the parent package in struts.xml:

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

<global-exception-mappings>
    <exception-mapping exception="java.lang.Exception" result="error" />
</global-exception-mappings>

But It seems to not able to catch those exceptions like requested resources, methods, pages are not found, I mean how to catch the struts2-level errors, and then I can do something to handle it.

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

You should define your unknown handler in the struts.xml. Unknown handlers are called by the framework, when an unknown action, result, or method are executed.

<bean type="com.opensymphony.xwork2.UnknownHandler" name="handler" class="com.package.SomeUnknownHandler"/> 

The class should implement UknownHandler interface to handle the cases:

  • when an action configuration is unknown
  • when a result cannot be found for an action and result code
  • when an action method cannot be found

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...