表达语言,不显示变量值 [英] Expression language, don't show variable value

查看:64
本文介绍了表达语言,不显示变量值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Java EE中非常陌生,我正在尝试使用.war文件 http://community .jboss.org/wiki/ThreadDumpJSP ,但是index.jsp文件似乎没有显示变量,我只看到${thr.name} ${thr.state} ${thr.priority} ${thr.daemon}我在jbosstomcat 6

I am pretty new in Java EE, i am trying use that .war file http://community.jboss.org/wiki/ThreadDumpJSP , but it seems index.jsp file doesn't show variable, I see only ${thr.name} ${thr.state} ${thr.priority} ${thr.daemon} I am tested it on jboss and tomcat 6

这是代码:

package org.jboss.varia.threaddump.ThreadDumpBean;

import java.io.Serializable;import java.util.*;

public class ThreadDumpBean implements Serializable {

    private final Map traces;

    public ThreadDumpBean() {traces = new TreeMap(THREAD_COMP);traces.putAll(Thread.getAllStackTraces());}

    public Collection getThreads() {return traces.keySet();}

    public Map getTraces() {return traces;}

    /*** Compare the threads by name and id.*/
    private static final Comparator THREAD_COMP = new Comparator() {  
        public int compare(Thread o1, Thread o2) {    
            int result = o1.getName().compareTo(o2.getName());    
            if (result == 0) {      
                Long id1 = o1.getId();      
                Long id2 = o2.getId();      
                return id1.compareTo(id2);    
            }    
            return result;  
        }};
}

.jsp:

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>

<jsp:useBean id="threadDump"
             class="org.jboss.varia.threaddump.ThreadDumpBean"
             scope="request"/>

<html>
<body>
<h2>Thread Summary</h2>
<table cellpadding="5" cellspacing="5">
  <tr>
    <th>Thread</th>
    <th>State</th>
    <th>Priority</th>
    <th>Daemon</th>
  </tr>
  <c:forEach items="${threadDump.threads}" var="thr">
    <tr>
      <td><c:out value='<a href="#${thr.id}">${thr.name}</a>' escapeXml="false"/></td>
      <td><c:out value="${thr.state}"/></td>
      <td><c:out value="${thr.priority}"/></td>
      <td><c:out value="${thr.daemon}"/></td>
    </tr>
  </c:forEach>
</table>

<h2>Thread Stack Traces</h2>
<c:forEach items="${threadDump.stackTraces}" var="trace">
  <h4><c:out value='<a name="${trace.key.id}">${trace.key}</a>' escapeXml="false"/></h4>
  <pre>
  <c:forEach items="${trace.value}" var="traceline">
      at <c:out value="${traceline}"/></c:forEach>
  </pre>
</c:forEach>

</body>
</html>

推荐答案

如果在Tomcat 6上部署JSP页面,则需要启用表达式语言才能使用它(出于向后兼容性的原因,默认情况下将其禁用).这可以通过创建一个web.xml文件(其中Servlet规范的版本至少设置为2.4)来完成.您的web.xml文件应如下所示:

If you deploy the JSP page on Tomcat 6 you need to enable the expression language to use it (for reasons of backwards compatibility this is disabled by default). That can either be done by creating a web.xml file where the version of the Servlet spec is set to at least 2.4. Your web.xml file should look something like this:

<web-app id="TreadDumpApp" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd";>

</web-app>

要在JSP标记属性之外使用EL,您需要在web.xml中添加更多事件魔术

To use EL outside JSP tag attributes, you need to add event more magic to the web.xml

<web-app {...magic from above...}>    
<jsp-property-group>  
<url-pattern>/*</url-pattern>  
<el-ignore>false</el-ignore>
</jsp-property-group>
</web-app>

您还应该能够强制此页面允许使用EL,但是可以在页面顶部添加以下声明:

You should also be able to force this single page to allow EL, but adding this declaration in the top of the page:

<%@ page isELIgnored ="false" %> 

是的,双重否定是相当优雅的,是吗? ;-)

Yeah, that double negation is quite elegant, eh? ;-)

这篇关于表达语言,不显示变量值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆