我想在单击特定文本时将客户端重定向到以下路径,但只有<a href="${userUrl}"> Query </a>和<a href="${removeUserUrl}"> Remove </a>可以正常工作。我的contextPath是"basics“,jsp的路径是"http://localhost:8080/basics/”。当我单击更新或添加用户时,它会将我重定向到"http://localhost:8080/basics/basics/users“( jsp文件是users.jsp),但它应该分别重定向到"http://localhost:8080/basics/user/update/${customer.id}”和"http://localhost:8080/basics/user/add“,这段代码有什么问题?
users.jsp:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Users</title>
//...style
</head>
<body>
<c:set value="${pageContext.request.contextPath}"
var="contextUrl" />
<c:set value="${contextUrl}/user/add" var="addUserUrl" />
<table style="width: 100%">
<tr>
<th>#ID</th>
<th>Name</th>
<th>Age</th>
<th>Country</th>
<td colspan="3"
style="background-color: #0CF323; text-align: center; border-top-color: #0CF323; border-right-color: #0CF323">
<a href="<c:url value='/user/add' />"> Add user </a>
</td>
</tr>
<c:forEach var="customer" items="${customers}">
<c:set value="${contextUrl}/user/update/${customer.id}"
var="updateUserUrl" />
<c:set value="${contextUrl}/user/remove/${customer.id}"
var="removeUserUrl" />
<c:set value="${contextUrl}/user/${customer.id}" var="userUrl" />
<tr>
<td><c:out value="${customer.id }" /></td>
<td><c:out value="${customer.name }" /></td>
<td><c:out value="${customer.age }" /></td>
<td><c:out value="${customer.country.country }" /></td>
<td style="background-color: #17D0F5"><a href="${userUrl}"> Query </a></td>
<td style="background-color: #FF8000"><a
href="${updateUserUrl}"> Update </a></td>
<td style="background-color: #EC2727"><a
href="${removeUserUrl}"> Remove </a></td>
</tr>
</c:forEach>
</table>
</body>
</html>发布于 2016-02-07 00:48:13
尝试替换以下内容:
<a href="<c:url value='/user/add' />"> Add user </a>使用双引号""并添加var="userVar":
<a href="<c:url value="/user/add" var="userVar" />">Add user</a>并在您想要的地方使用${userVar}。
https://stackoverflow.com/questions/35243281
复制相似问题