ServletContext.getRequestDispatcher()vs ServletRequest.getRequestDispatcher() [英] ServletContext.getRequestDispatcher() vs ServletRequest.getRequestDispatcher()

查看:313
本文介绍了ServletContext.getRequestDispatcher()vs ServletRequest.getRequestDispatcher()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么


getLquestDispatcher(字符串路径)
ServletRequest接口不能
延伸到当前servlet之外
context

getRequestDispatcher(String path) of the ServletRequest interface cannot extend outside the current servlet context

其中


getLquestDispatcher(String path)
ServletContext可以使用
getContext(String uripath)方法
获取资源$ RequestDispatcher b $ b在国外背景下。

getRequestDispatcher(String path) of the ServletContext can use the getContext(String uripath) method to obtain RequestDispatcher for resources in foreign contexts.

以及如何?

请帮助

推荐答案

如果使用绝对路径,例如(/ index.jsp),没有区别。

If you use an absolute path such as ("/index.jsp"), there is no difference.

如果使用相对路径,则必须使用 HttpServletRequest.getRequestDispatcher() ServletContext.getRequestDispatcher()不允许。

If you use relative path, you must use HttpServletRequest.getRequestDispatcher(). ServletContext.getRequestDispatcher() doesn't allow it.

例如,如果您在<$上收到请求c $ c> http://example.com/myapp/subdir ,

    RequestDispatcher dispatcher = 
        request.getRequestDispatcher("index.jsp");
    dispatcher.forward( request, response ); 

将请求转发到页面 http://example.com/ myapp / subdir / index.jsp

在任何情况下,您都不能将请求转发到上下文之外的资源。

In any case, you can't forward request to a resource outside of the context.

这篇关于ServletContext.getRequestDispatcher()vs ServletRequest.getRequestDispatcher()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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