Java 如何在Struts2中从自定义动作映射器返回全局结果
如何在自定义操作映射器中返回自定义全局结果Java 如何在Struts2中从自定义动作映射器返回全局结果,java,struts2,Java,Struts2,如何在自定义操作映射器中返回自定义全局结果 public class MyCustomActionMapper implements ActionMapper { public ActionMapping getMapping(HttpServletRequest request, ConfigurationManager configManager) { .... .... return ???
public class MyCustomActionMapper implements ActionMapper {
public ActionMapping getMapping(HttpServletRequest request,
ConfigurationManager configManager) {
....
....
return ????
}
}
ActionMappingGetMappingJavax.servlet.http.HttpServletRequest请求, 配置管理器配置管理器
Expose the ActionMapping for the current request
Parameters:
request - The servlet request
configManager - The current configuration manager
Returns:
The appropriate action mapping String or null if mapping cannot be determined
你确定这是你真正需要做的吗?Struts2为您提供了开箱即用的所有工具,以实现几乎所有的结果 但是如果你真的想实现你的自定义动作映射器,那么看看第9章,从266页到269页,共页 ActionMapper接口提供两种方法:一种是将URL转换为动作映射,另一种是以另一种方式将动作映射转换为URL 因此,您可以像往常一样从struts.xml映射操作和结果类型,而不是在操作映射器中 看一看太。。。任何地方都没有结果类型,这不是管理它们的地方
public ActionMapping getMapping(HttpServletRequest request,
ConfigurationManager configManager) {
ActionMapping mapping = new ActionMapping();
String uri = getUri(request);
int indexOfSemicolon = uri.indexOf(";");
uri = (indexOfSemicolon > -1) ? uri.substring(0, indexOfSemicolon) : uri;
uri = dropExtension(uri, mapping);
if (uri == null) {
return null;
}
parseNameAndNamespace(uri, mapping, configManager);
handleSpecialParameters(request, mapping);
if (mapping.getName() == null) {
return null;
}
parseActionName(mapping);
return mapping;
}
无法返回ie自定义全局结果,因为全局结果不是操作。我理解正确吗?谢谢你的回答,当一个请求有错误的子域时,我需要返回一些页面。然后必须通过拦截器来完成。当然,你可以通过拦截器来完成。搜索等等,它充满了关于如何做到这一点的答案,我知道,我只是不想创建用于检查子域正确性的拦截器。Action mapper已经用于自己的目的,所以我想检查Action Mapperit方法中的子域,子域存在于我们的站点上子域是countryOk的区域。你可能想看看