开发者

Parse a custom tag using request information in JSP

I have a simple problem but I haven't had any luck finding the solution with Google.

I want to expand custom JSP tags but I want to be able to parse it differently depending on request information. For example the tag:

<my:tag type="..."/>

Should be expanded d开发者_开发知识库ifferently if the parameters in the request differ:

http://localhost:8080/context/servlet?arg=web

Should yield a different result than:

http://localhost:8080/context/servlet?arg=mobile

Does anybody know how the tag parsing class (usually expands TagSupport) can access or be passed parameters from the request?


You could use the Expression Language to supply the request parameter to your JSP-Tag.

<my:tag type="${param.arg}"/>


Inside the tag class, you can access the request object and get the parameter by

this.pageContext.getRequest().getParameter("arg");


You can access it through the getParameter() method of HttpServletRequest object.

String arg1 = request.getParameter("arg");

There, you have the variable arg1 that contains "web" or "mobile" when hit from different URL as in your 2 examples.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜