1

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 differently 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?

jd.
  • 4,057
  • 7
  • 37
  • 45

3 Answers3

2

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

<my:tag type="${param.arg}"/>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
stacker
  • 68,052
  • 28
  • 140
  • 210
0

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.

Daniel Baktiar
  • 1,692
  • 11
  • 22
  • I understand that but the request.getParameter method is not available from the context of a TagSupport class. – jd. Feb 25 '11 at 15:36
0

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

this.pageContext.getRequest().getParameter("arg");
Tommy Siu
  • 1,265
  • 2
  • 10
  • 24