【问题标题】:Spring MVC: best way to set global debug flagSpring MVC:设置全局调试标志的最佳方法
【发布时间】:2010-09-23 18:24:09
【问题描述】:

我正在使用 Spring MVC,而我的 jsp 有一个

<div id="debug">

我希望在开发过程中能够有条件地显示/关闭的部分。例如,如果我正在查看页面 www.example.com/main,www.example.com/main?debug=1 会显示包含在调试 div 下的信息。

有没有简单的方法来做到这一点?我可以使用 URL 参数,我应该使用 cookie 吗?如果您有任何想法,我将不胜感激。

【问题讨论】:

    标签: java spring jsp spring-mvc


    【解决方案1】:

    将其设置为web.xml中的上下文参数。

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

    并通过${initParam} 在EL 中访问它,它基本上是指带有所有上下文参数的Map&lt;String, String&gt;。这是 JSTL c:if 的示例:

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

    可能有更多我不知道的“弹性”解决方案。但是在标准 JSP/Servlet API 的帮助下,这并不难:)

    【讨论】:

      猜你喜欢
      • 2011-01-17
      • 1970-01-01
      • 1970-01-01
      • 2013-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-13
      • 1970-01-01
      相关资源
      最近更新 更多