加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – Servlet:如何获取自己的URL模式?

发布时间:2020-12-15 05:03:01 所属栏目:Java 来源:网络整理
导读:servlet或过滤器可以查找自己的URL模式吗? 意思是,如果我将一些servlet或过滤器绑定到/ first / *和/ second / *并且请求进来,我可以找出这两个模式中的哪一个触发了它吗? 即使servlet只绑定到一个模式,有没有办法从servlet内部查找(而不是硬编码一个值)?
servlet或过滤器可以查找自己的URL模式吗?

意思是,如果我将一些servlet或过滤器绑定到/ first / *和/ second / *并且请求进来,我可以找出这两个模式中的哪一个触发了它吗?

即使servlet只绑定到一个模式,有没有办法从servlet内部查找(而不是硬编码一个值)?

解决方法

HttpServletRequest类上的这个方法可以帮到你.您将在HTTP请求调用的任何Servlet方法上获得HttpServletRequest的实例.

getServletPath

java.lang.String getServletPath() Returns the part of this request’s
URL that calls the servlet. This path starts with a “/” character and
includes either the servlet name or a path to the servlet,but does
not include any extra path information or a query string. Same as the
value of the CGI variable SCRIPT_NAME.

看看这个:

http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#getServletPath()

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读