调用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开普勒
<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>
uploadImages是一个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的版本不同。我不知道正确的版本。
最佳答案
首先,不要使用Scriptlets(<%= %>)
获取循环索引,可以通过定义<c:forEach
从varStatus
标记获取索引。
正在考虑您已添加uploadedImages
(Map
)对象以在servlet上进行请求。
req.setAttribute("uploadedImages", uploadedImages);
从jsp中的
uploadedImage
映射迭代uploadedImages
对象的操作如下:在您的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>
从DTO的expression-language(
${ }
)或jstl(<c:
tag)中获取属性值的方法如下:在EL中:
${uploadedImage.value.documentName} <!--internally EL will invoke getDocumentName() to get documentName value-->
在JSTL中:
<c:out value="${uploadedImage.value.documentName}"/>