How to add custom VariableResolver to JSP Context in Jsp 2.0 to support special EL?

Deadly 提交于 2019-12-24 11:26:56

问题


I'm building my own JSP Tag Library which need to support some features that Application developers can use like this:

<w:user-label id="usrlb" value="${session.user}"/>
<w:textbox id="tb" label="User Name" value="${usrlb.value.name}"/>

which means I want my EL can interact with my Tag declaration. and also I need to add stack concept into this library to support "id namespace" or something.

My current research leads me to wrap default JspFactory like this:

JspFactory.setDefaultFactory(new JspFactoryImpl(JspFactory.getDefaultFactory()));

Which could work in Tomcat5.5 although it's not a good idea. Is there any other more pretty way to do that?


回答1:


You could have your <w:user-label /> tag class simply add a variable to one of the context' scopes (request, session, ...) so EL expressions can find it? If the bean you add to the scope follows JavaBeans conventions, nested properties should be available using EL.




回答2:


You can just define your tag attributes with <rtexprvalue>false</rtexprvalue>, then you will receive expressions as Strings which you can parse manually.



来源:https://stackoverflow.com/questions/1979624/how-to-add-custom-variableresolver-to-jsp-context-in-jsp-2-0-to-support-special

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!