jsp页面中使用JSTL标签库的<c>的一些看法和疑问?

我在jsp页面中使用JSTL标签库的<c:redirect>的一些疑问?

本篇文章没写完(写了一部分后,我就去忙其他的了,后来再回来写,思路就断了,接不上了,就重新写了一篇),可以直接看这篇文章

直接看代码

goodsList.jsp商品列表页面

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!-- 
如果直接在地址栏中输入jsp页面的网址http://localhost:8888/jmBookShop/goodsList.jsp访问的话,
就判断在该页面中的request对象中是否保存了商品集合列表的数据,如果request对象中没有保存商品集合列表的数据,就直
接跳转(重定向)到goodsServlet?operateType=fore这个地址
 -->
<c:if test="${requestScope.goods == null}">
<c:redirect url="goodsServlet?operateType=fore"></c:redirect>
</c:if>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>商品信息列表-囧萌软件有限公司,雪豹软件工作室,江西省赣州市于都县</title>
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/background/css/body.css"
	media="all">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/background/css/mark.css">
	<style type="text/css">
	body{
	font-weight: bold;
	}
	</style>
</head>
<body>
<center>
<font style="font-size: 22px;">
商品编号     
商品    
原价    
囧萌价    
<a class="submitOrderA" href="${pageContext.request.contextPath}/ShoppingCartServlet?operateType=look">
我的购物车
</a>
<a title="囧萌网上商城-雪豹软件工作室-江西省赣州市于都县" href="${pageContext.request.contextPath}/login.jsp">
登录
</a>
</font>

<c:forEach var="goodsItem" items="${requestScope.goods}">
<div class="goodsDiv">
<img  height="100px" title="${goodsItem.goodsName}" src="${pageContext.request.contextPath}/img/16.jpg">
${goodsItem.goodsId}    
${goodsItem.goodsName}    
${goodsItem.originalPrice}    
${goodsItem.discountPrice}    
<a href="ShoppingCartServlet?goodsId=${goodsItem.goodsId}&operateType=add" title="${goodsItem.goodsName}">
加入购物车
</a>

</div>
<br>
</c:forEach>
</center>
</body>
</html>

我在该页面写了这句话,<c:if test="${requestScope.goods == null}"><c:redirect url="goodsServlet?operateType=fore"></c:redirect></c:if>,goodsList.jsp页面是商品信息列表的展示页面,是从goodsServlet这个Servlet中跳转到goodsList.jsp页面,但是怕有些人直接在浏览器地址栏中直接访问goodsList.jsp页面,如果是直接访问goodsList.jsp页面的话,那goodsList.jsp页面就会没有数据,所以我在goodsList.jsp页面的开头的地方写了判断,如果${requestScope.goods == null}为空的话,那就重定向到goodsServlet这个Servlet,所以问题来了啊,<c:redirect url="goodsServlet?operateType=fore"></c:redirect>这句话中的url属性的值开头要不要带斜杠,我带着好奇的心情,试了好几种写法,

 

第一种<c:redirect url="goodsServlet?operateType=fore"></c:redirect>

第二种<c:redirect url="/goodsServlet?operateType=fore"></c:redirect>

第三种<c:redirect url="${pageContext.request.contextPath}/goodsServlet?operateType=fore"></c:redirect>这里的${pageContext.request.contextPath}是获取项目名称(即/jmBookShop)

可是结果却大跌眼镜

第一种结果是OK的,没问题,看截图,可以正常访问,这里我们可以理解,因为url="goodsServlet?operateType=fore"这里不加斜杠,其实就是代表从项目的根目录开始,项目的根目录,明白吧,项目的根目录也就是http://localhost:8888/jmBookShop

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值