使用 Struts2 显示未找到操作的错误页面 [英] Show Error Page for No Action found using Struts2
问题描述
我想处理 url 中没有操作或结果的错误情况,或者向某些 url 添加永久重定向.
I want to handle error condition for no action or result present in url or add permenant redirect to some urls.
当用户输入一些不存在或已迁移的网址时,他会收到错误
When user enter some url which does not exist or is migrated then he gets an error
HTTP 状态 404 - 没有为操作定义结果com.zyx.pqr.action.AbcAction$$EnhancerByCGLIB$$c95cf377 和结果错误
HTTP Status 404 - No result defined for action com.zyx.pqr.action.AbcAction$$EnhancerByCGLIB$$c95cf377 and result error
我们可以以更好的方式处理未找到的页面并跟踪应该永久重定向的页面或类似内容的任何方式.
Any way in which we can handle page not found in a better way and also track pages which should permanent redirect or something like that.
在堆栈跟踪或控制台中没有什么可添加的,只是想知道如何处理全局操作错误和全局重定向.
Well nothing to add in stack trace or console, just wanted to know how global action error and global redirects can be handled.
推荐答案
从 Struts2 2.1 版开始,就有了 Unknown Handlers
堆栈.
Since Struts2 version 2.1 there is Unknown Handlers
stack.
未知处理程序在执行未知操作、结果或方法时调用.您需要实现 com.opensymphony.xwork2.UnknownHandler
接口并将您的 Unknown Handlers 定义添加到您的 struts.xml
文件中.
Unknown Handlers are called when an unknown action, result, or method are executed. You need to implement com.opensymphony.xwork2.UnknownHandler
interface and add your Unknown Handlers definition to your struts.xml
file.
参见 http://struts.apache.org/development/2.x/docs/unknown-handlers.html.
这篇关于使用 Struts2 显示未找到操作的错误页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!