views:

39

answers:

1

I'm using Spring MVC and my jsp's have a

<div id="debug">

section that I would like to be able to show/turn off conditionally while we are in development. For example, if I am looking at page www.example.com/main, www.example.com/main?debug=1 would show me the information that is contained under the debug div.

Is there an easy way to do this? Can I use a URL parameter, should I use a cookie? I would appreciate any ideas you have.

+1  A: 

Set it as context parameter in web.xml.

<context-param>
    <param-name>debug</param-name>
    <param-value>true</param-value>
</context-param>

And access it in EL by ${initParam} which basically refers to a Map<String, String> with all context parameters. Here's an example with JSTL c:if:

<c:if test="${initParam.debug}">
    <div>Debug mode!</div>
</c:if>

There may be more "Springy" solutions for this which I am not aware of. But it's not that hard with help of standard JSP/Servlet API's :)

BalusC
I tried this and it works fine. Thanks!
robert
You're welcome :)
BalusC
I tried this and it works. Thanks!
robert