Expression language, don't show variable value
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
edit:
here is code:
package org.jboss.varia.threaddump.ThreadDumpBean;
import java.io.Serializable;import java.util.*;
public class ThreadDumpBean implements Serializable {
pri开发者_Python百科vate 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;
}};
}
and .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>
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>
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>
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? ;-)
精彩评论