开发者

Cannot access implict object from within method in custom JSP tag file

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 app开发者_运维百科reciated.


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.

<%!
private String process(String age, BigDecimal amount, ServletRequest request) {
   String url=request.getURL;
   ....
}
%>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜