为什么有魔法的属性在Servlet规范暴露? [英] Why are there magic attributes exposed in the Servlet spec?

查看:140
本文介绍了为什么有魔法的属性在Servlet规范暴露?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它总是显得有些在使用Java的原则相抵触的Java Servlet规范(2.5版的这里)包括一组包含约包括资源,即信息魔法属性:

It's always seemed a little at odds with the principles of Java that the Java Servlet Spec (2.5 version here) includes a set of magic attributes containing info about included resources, namely:

javax.servlet.include.request_uri
javax.servlet.include.context_path
javax.servlet.include.servlet_path
javax.servlet.include.path_info
javax.servlet.include.query_string

这不是甚至专门在 API文档,只有在它是正确执行必须的。规格

It's not even specifically pointed out in the API documentation, only in the spec where it is a must for correct implementation.

这个方法感觉很不对劲,暴露的实现细节客户端将使用并依赖。为什么以这种方式暴露这些信息?

This approach feels very wrong, an exposed implementation detail that clients will use and depend on. Why is this information exposed in this way?

推荐答案

他们的API文档中实际上规定,在的常量字段值一部分。当你的API文档中看到的,你应该使用的 的RequestDispatcher 代替,例如:

They are actually specified in the API documentation, in the Constant Field Values part. As you see in the API documentation, you are supposed to use the constants of RequestDispatcher instead, e.g:

String includeRequestURI = request.getAttribute(RequestDispatcher.INCLUDE_REQUEST_URI);

这篇关于为什么有魔法的属性在Servlet规范暴露?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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