我对 Java EE 还很陌生,我正在尝试使用它 .war
文件http://community.jboss.org/wiki/ThreadDumpJSP ,但似乎index.jsp
文件不显示变量,我只看到 ${thr.name} ${thr.state} ${thr.priority} ${thr.daemon}
我在jboss
上进行了测试和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 文件应如下所示:
<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中添加更多魔法事件
<web-app {...magic from above...}>
<jsp-property-group>
<url-pattern>/*</url-pattern>
<el-ignore>false</el-ignore>
</jsp-property-group>
</web-app>
您还应该能够强制此单个页面允许 EL,但在页面顶部添加此声明:
<%@ page isELIgnored ="false" %>
是啊,双重否定很优雅,嗯? ;-)
关于java - 表达式语言,不显示变量值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6505107/