无法从自定义 JSP 标记文件中的方法内访问隐式对象
我正在尝试创建自定义 jsp 标记。一切工作正常,除了我的请求似乎超出了我的自定义函数的范围。
以下是 .tag 文件中的相关部分:
<%!
private String process(String age, BigDecimal amount)
{
//Attempting to access request here results in an compile time error trying to:
String url=request.getURL;
}
%>
我对 JSP 非常陌生,所以我确信我遗漏了一些明显的东西..但我似乎不知道是什么。任何帮助表示赞赏。
I'm attempting to create a custom jsp tag. Everything is working fine, except for the fact that I the request seems to be out-of-scope for my custom function.
Here is the relevant bit from the .tag file:
<%!
private String process(String age, BigDecimal amount)
{
//Attempting to access request here results in an compile time error trying to:
String url=request.getURL;
}
%>
I'm very new to JSP so I'm sure I'm missing something obvious..but I can't seem to figure out what. Any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我怀疑这是因为自定义函数本身不是在 JSP 服务调用的主执行中定义的,而是在生成的 JSP 类中定义为单独的方法。因此,
request
变量对其隐式不可见。为了澄清这一点,如果您查看了 JSP 编译器生成的 java 源代码(特定于应用程序服务器),您将看到它是如何挂在一起的。
我认为您必须将请求对象声明为函数的参数,并在调用它时将其传入。
I suspect that's because the custom function itself is not defined within the main execution of the JSP's service call, but is defined as a separate method within the generated JSP class. As such, the
request
variable is not visible tot it implicitly.To clarify, if you had a look at the java source that the JSP compiler generates (which is appserver specific), you'll see how it hangs together.
I think you'll have to declare the request object as a parameter to your function, and pass it in when you invoke it.