一个转发请求的问题

linshenxiu 2010-02-09 10:07:01
我有一个index.jsp页面,进来以后先检查requestScope中有无types键。若没有,就跳向servlet去获取,然后再由servlet转发请求到index.jsp页。代码是这样写的:
页面部分:

<c:if test="${requestScope.classss==null}">
<jsp:forward page="servlet/TypeServlet"></jsp:forward>
</c:if>
<c:if test="${requestScope.types!=null}">
Hello World!
</c:if>

servlet部分

List listTypes=new TypeBizImpl().getTypesByClassId(1);
request.setAttribute("types", listTypes);
RequestDispatcher rd=request.getRequestDispatcher("../index.jsp");
rd.forward(request, response);

可是运行的时候却出现了死循环!
如果从servlet转发到其他页面,在其他页面里取types的值,是可以取到的。那为什么转发到原始页index.jsp,会出现死循环呢?
...全文
173 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
linshenxiu 2010-02-09
  • 打赏
  • 举报
回复
谢谢大家了。真的是我写错了,呵呵,马虎了。
awusoft 2010-02-09
  • 打赏
  • 举报
回复
你判断的不是types是不是空吧?

<c:if test="${requestScope.classss==null}">==>是不是应该换成="${requestScope.types==null}啊?"
<jsp:forward page="servlet/TypeServlet"></jsp:forward>
</c:if>
<c:if test="${requestScope.types!=null}">
Hello World!
</c:if>
dichyzhu 2010-02-09
  • 打赏
  • 举报
回复
request是同一个请求,你试一下。
linshenxiu 2010-02-09
  • 打赏
  • 举报
回复
types储存的集合绝对不为空,难道是转发的时候types丢掉了?
fengshiyan1943 2010-02-09
  • 打赏
  • 举报
回复

List listTypes=new TypeBizImpl().getTypesByClassId(1);

if(listTypes!=null)
{
request.setAttribute("types", listTypes);
RequestDispatcher rd=request.getRequestDispatcher("../index.jsp");
rd.forward(request, response);
}
else
{
int count =1;
request.setAttribute("types", count);
RequestDispatcher rd=request.getRequestDispatcher("../index.jsp");
rd.forward(request, response);

}


楼主看看这个吧 。
dumbant 2010-02-09
  • 打赏
  • 举报
回复
LZ先确定list在servlet和JSP中是不是NULL,在两个地方都把值遍历出来看看。
zt3862266 2010-02-09
  • 打赏
  • 举报
回复
是不是有过滤器写的有问题,造成死循环呢?
楼主看看
fengshiyan1943 2010-02-09
  • 打赏
  • 举报
回复
List listTypes=new TypeBizImpl().getTypesByClassId(1);
request.setAttribute("types", listTypes);
RequestDispatcher rd=request.getRequestDispatcher("../index.jsp");
rd.forward(request, response);

佩服 。。。
types 是 List 集合. 你直接 requestScope.types 肯定是空
把types循环出来.取字段在判断




  • 打赏
  • 举报
回复
判断listTypes这个为空不为空。。。。。
lstar66 2010-02-09
  • 打赏
  • 举报
回复

request.setAttribute("types", listTypes);
linshenxiu 2010-02-09
  • 打赏
  • 举报
回复
劳烦各位再帮我看看吧
linshenxiu 2010-02-09
  • 打赏
  • 举报
回复
不好意思,是我打错了,可将classs改成types也还是死循环

<c:if test="${requestScope.types==null}">
<jsp:forward page="servlet/TypeServlet"></jsp:forward>
</c:if>
<c:if test="${requestScope.types!=null}">
Hello World!
</c:if>

fengshiyan1943 2010-02-09
  • 打赏
  • 举报
回复
<c:if test="${requestScope.classss==null}">
<jsp:forward page="servlet/TypeServlet"></jsp:forward>
</c:if>

这永远是空的 不死循环才乖.. 你打错单词了吧 。


<c:if test="${requestScope.types!=null}">
Hello World!
</c:if>
蛋黄车 2010-02-09
  • 打赏
  • 举报
回复
<c:if test="${requestScope.classss==null}">
<jsp:forward page="servlet/TypeServlet"></jsp:forward>
</c:if>
<c:if test="${requestScope.types!=null}">
Hello World!
</c:if>

不仔细噢!
lcb520 2010-02-09
  • 打赏
  • 举报
回复

<c:if test="${requestScope.classss==null}">
classss是什么啊
下面是
<c:if test="${requestScope.types!=null}">

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧