调用jsp页面时EL标记不呈现。
<c:out value="${uploadedImage.value.getDocumentName()}"/>
打印$ {uploadedImage.value.getDocumentName()}
我的pom文件是
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<url>http://maven.apache.org</url>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.9</version>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.4.Final</version>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
<version>7.0.12</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-el-api</artifactId>
<version>7.0.12</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jsp-api</artifactId>
<version>7.0.12</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
<build>
<finalName>ImageManagement</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
我的web.xml是
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
</web-app>
Web应用程序具有所有Servlet映射。
我的项目配置是 Tomcat 7.0 Eclipse kepler
<c:if test = "${not empty uploadedImages}">
<% int i = 0; %>
<c:forEach var="uploadedImage" items="${uploadedImages}">
<tr>
<% i++; %>
<td><%= i %></td>
<td><c:out value="${uploadedImage.value.getDocumentName()}"/></td>
<td><c:out value="${uploadedImage.value.getDocumentSize()}"/></td>
<!-- <td><img src="image?id=${uploadedImage.value.getUserRepositryId()}" style = "height : 80px; width : 50px" alt = "image here"/></td>-->
<td>
<a href = "delete?id=${uploadedImage.value.getUserRepositryId()}"> Delete </a>
<a href = "edit?id=${uploadedImage.value.getUserRepositryId()}"> Edit </a>
</td>
</tr>
</c:forEach>
</c:if>
uploadedImages是一个HashMap变量,它设置为Session对象。 它从数据库中获取已保存的图像并将其保存为HashMap。 数据库部分工作正常,它从数据库加载图像并将它们保存在HashMap中。
唯一的问题是工作EL标签。 这个项目在没有maven的情况下工作正常。
UserRepositryDTO.java
public class UserRepositryDTO {
private int userRepositryId;
private int userId;
private String documentName;
private long documentSize;
private byte[] document;
private String message;
/**
* @return the message
*/
public String getMessage() {
return message;
}
/**
* @param message the message to set
*/
public void setMessage(String message) {
this.message = message;
}
/**
* @return the userRepositryId
*/
public int getUserRepositryId() {
return userRepositryId;
}
/**
* @return the userId
*/
public int getUserId() {
return userId;
}
/**
* @return the documentName
*/
public String getDocumentName() {
return documentName;
}
/**
* @return the documentSize
*/
public long getDocumentSize() {
return documentSize;
}
/**
* @return the document
*/
public byte[] getDocument() {
return document;
}
/**
* @param userRepositryId the userRepositryId to set
*/
public void setUserRepositryId(int userRepositryId) {
this.userRepositryId = userRepositryId;
}
/**
* @param userId the userId to set
*/
public void setUserId(int userId) {
this.userId = userId;
}
/**
* @param documentName the documentName to set
*/
public void setDocumentName(String documentName) {
this.documentName = documentName;
}
/**
* @param documentSize the documentSize to set
*/
public void setDocumentSize(long documentSize) {
this.documentSize = documentSize;
}
/**
* @param document the document to set
*/
public void setDocument(byte[] document) {
this.document = document;
}
}
UserDTO.java
public class UserDTO {
private int userId;
private String username;
private String message;
private long totalSize;
private Map<Integer,UserRepositryDTO> userRepositry;
/**
* @return the totalSize
*/
public long getTotalSize() {
return totalSize;
}
/**
* @param totalSize the totalSize to set
*/
public void setTotalSize(long totalSize) {
this.totalSize = totalSize;
}
/**
* @return the userId
*/
public int getUserId() {
return userId;
}
/**
* @return the username
*/
public String getUsername() {
return username;
}
/**
* @return the message
*/
public String getMessage() {
return message;
}
/**
* @param userId the userId to set
*/
public void setUserId(final int userId) {
this.userId = userId;
}
/**
* @param username the username to set
*/
public void setUsername(final String username) {
this.username = username;
}
/**
* @param message the message to set
*/
public void setMessage(final String message) {
this.message = message;
}
public Map<Integer,UserRepositryDTO> getUserRepositry() {
return userRepositry;
}
public void setUserRepositry(Map<Integer,UserRepositryDTO> userRepositry) {
this.userRepositry = userRepositry;
}
}
问题是由于servlet jsp jstl的版本不同。我不知道正确的版本。
答案 0 :(得分:0)
首先,不要使用Scriptlets(<%= %>)
获取循环索引,您可以通过定义<c:forEach
从varStatus
代码获取索引。
我们正在考虑您已在servlet上添加了uploadedImages
(Map
)个对象。
req.setAttribute("uploadedImages", uploadedImages);
用于从uploadedImage
迭代uploadedImages
对象在jsp中执行以下操作:
在jsp的顶部导入jstl taglib:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
然后,
<c:choose>
<c:when test="${not empty uploadedImages}">
<c:forEach var="uploadedImage" items="${uploadedImages}" varStatus="status">
<tr>
<!--Her, don't use Scriptlets to get index, get index from <c:forEach varStatus -->
<td>${status.index}</td>
<td><c:out value="${uploadedImage.value.documentName}"/></td>
<td><c:out value="${uploadedImage.value.documentSize}"/></td>
<!-- <td><img src="image?id=${uploadedImage.value.userRepositryId}" style = "height : 80px; width : 50px" alt = "image here"/></td>-->
<td>
<a href = "delete?id=${uploadedImage.value.userRepositryId}"> Delete </a>
<a href = "edit?id=${uploadedImage.value.userRepositryId}"> Edit </a>
</td>
</tr>
</c:forEach>
</c:when>
<c:otherwise>
uploadedImages Map is empty..
</c:otherwise>
<c:choose>
从表达式语言(${ }
)或jstl(<c:
标签)中获取DTO的价值,请执行以下操作:
:
${uploadedImage.value.documentName} <!--internally EL will invoke getDocumentName() to get documentName value-->
在JSTL中:
<c:out value="${uploadedImage.value.documentName}"/>
答案 1 :(得分:0)
您需要修复您的web.xml。它声明它使用的Servlet 2.3等同于不支持EL的JSP 1.2。
尝试使用以下内容:
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0"
metadata-complete="true">
</web-app>