当我点击某个类别时,它会显示该类别的产品列表,网址为:
http://localhost:9999/toyshop/home?category=Đồ%20chơi%20theo%20phim
但是当我点击下一个分页页面时,网址将是
http://localhost:9999/toyshop/home?category{Đồ%20chơi%20theo%20phim}=Đồ%20chơi%20theo%20phim&page=2
这是我的jsp代码:
<c:remove var="param" scope="session" />
<c:remove var="paramValue" scope="session" />
<c:remove var="href" scope="session" />
<c:remove var="param" scope="request" />
<c:remove var="paramValue" scope="request" />
<c:remove var="href" scope="request" />
<c:choose>
<c:when test="${not empty sessionScope.productName}">
<c:set var="servlet" value="search"/>
<c:set var="param" value="product"/>
<c:set var="paramValue" value="${sessionScope.productName}"/>
</c:when>
<c:when test="${not empty sessionScope.categoryName}">
<c:set var="servlet" value="home"/>
<c:set var="param" value="category"/>
<c:set var="paramValue" value="${sessionScope.categoryName}"/>
</c:when>
<c:otherwise>
<!-- Handle the case where both are empty -->
<c:set var="servlet" value="home"/>
<c:set var="param" value=""/>
<c:set var="paramValue" value=""/>
</c:otherwise>
</c:choose>
<c:choose>
<c:when test="${empty paramValue}">
<c:set var="href" value="${servlet}?"/>
</c:when>
<c:otherwise>
<c:set var="href" value="${servlet}?${param}=${paramValue}"/>
</c:otherwise>
</c:choose>
<c:if test="${currentPaginationPage > 1}">
<a href="${href}&page=${currentPaginationPage - 1}" class="pagination__item">
<i class="pagination__icon fas fa-chevron-left"></i>
</a>
</c:if>
<c:if test="${startPage > 1}">
<div class="pagination__item pagination__item--none">...</div>
</c:if>
<c:forEach begin="${startPage}" end="${endPage}" var="page">
<c:choose>
<c:when test="${page == currentPaginationPage}">
<a href="${href}&page=${page}" class="pagination__item pagination__item--active">${page}</a>
</c:when>
<c:otherwise>
<a href="${href}&page=${page}" class="pagination__item">${page}</a>
</c:otherwise>
</c:choose>
</c:forEach>
<c:if test="${endPage < totalPaginationPage}">
<div class="pagination__item pagination__item--none">...</div>
</c:if>
<c:if test="${currentPaginationPage < totalPaginationPage}">
<a href="${href}&page=${currentPaginationPage + 1}" class="pagination__item">
<i class="pagination__icon fas fa-chevron-right"></i>
</a>
</c:if>
我期待网址是
http://localhost:9999/toyshop/home?category=Đồ%20chơi%20theo%20phim&page=2
${param}
是EL中的保留变量。它基本上是一个HttpServletRequest#getParameterMap()
的外观。您不应该删除/覆盖它。
使用与
${param}
不同的名称。例如。 ${paramName}
。
<c:set var="paramName" value="category"/>
<c:set var="paramValue" value="${sessionScope.categoryName}"/>
<c:set var="href" value="${servlet}?${paramName}=${paramValue}"/>