gpt4 book ai didi

java - JSP 和 servlet 中页面路径的概念

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:13:04 25 4
gpt4 key购买 nike

这两者有什么区别?

在 JSP 中:

${pageContext.request.contextPath} 

如果在 servlet 中不使用表达式语言进行编码,如何实现相同的结果?

在 servlet 中:

request.getServletPath() 

如果用 JSP 编码如何实现相同的结果?

最佳答案

${pageContext.request.contextPath} : 返回请求 URI 中指示请求上下文的部分。事实上,它与 request.getContextPath() 相同,因为 ${pageContext.request} 指的是当前请求的 HttpServletRequest

例如:

http://localhost:80/myapplication/path/servlet

  • ${pageContext.request.contextPath} 返回 /myapplication

  • request.getServletPath() 返回此请求的 URL 中调用 servlet 的部分,例如/path/servlet

  • ${pageContext.request.servletPath} 返回 /path/servlet

关于java - JSP 和 servlet 中页面路径的概念,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14096956/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com