Tomcat 无法获取另一个 webapp 的 ServletContext [英] Tomcat not able to get ServletContext of another webapp

查看:36
本文介绍了Tomcat 无法获取另一个 webapp 的 ServletContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 tomcat 6 并且我有两个 web 应用程序.一个是 webapp1,另一个是 webapp2.从 webapp2 中的过滤器,我试图访问另一个 webapp,即 webapp1.我的过滤器代码如下

I am using tomcat 6 and I have two webapps. One is webapp1 and the other one is webapp2. From a filter inside webapp2, I am trying to access the other webapp i.e webapp1. My Filter code is something like below

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

    HttpServletRequest req = (HttpServletRequest)request;
    System.out.println("requeted path = " + req.getRequestURI());

    ServletContext othercontext = confg.getServletContext().getContext("/webapp1");
    RequestDispatcher dispatcher = othercontext.getRequestDispatcher(req.getRequestURI());
    dispatcher.forward(request, response);
    chain.doFilter(request, response);
}

知道我做错了什么吗?我总是得到 null 作为 othercontext 值.

Any Idea what I am doing wrong ? I am always getting null as the othercontext value.

推荐答案

在 server.xml 中设置 crossContext = "true".请参阅上下文容器的文档.

Set crossContext = "true" in the server.xml. See the documentation for the context container.

如果您想在内部调用,请设置为 true这个应用程序ServletContext.getContext() 到成功返回请求其他 Web 应用程序的调度程序在这个虚拟主机上运行.调成安全性中的 false(默认值)有意识的环境,使getContext() 总是返回 null.

Set to true if you want calls within this application to ServletContext.getContext() to successfully return a request dispatcher for other web applications running on this virtual host. Set to false (the default) in security conscious environments, to make getContext() always return null.

这篇关于Tomcat 无法获取另一个 webapp 的 ServletContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆