2011-02-03 126 views
0

我试图使用重定向标记来将索引页导向驻留在我的web项目的JSP文件夹中的主页。我的项目的层次结构下:JSTL错误(HTTP状态404 -/JSTL/home)

 
WEB-INF 
    jsp 
     home.jsp 
index.jsp 

我同时使用JSTL库1.2和standard.jar 以下是我的index.jsp

<%@ taglib prefix="core" uri="/tags/c" %> 

<core:redirect url="/home"></core:redirect> 

的代码时,我运行项目我收到以下错误;

 
HTTP Status 404 - /JSTL/home 
type Status report 
message /JSTL/home 
description The requested resource (/JSTL/home) is not available. 

回答

1

/WEB-INF中的文件不可公开访问(在浏览器地址栏中输入地址时不可用)。 <jsp:include>和任何使用RequestDispatcher的servlet是唯一可以访问它们的servlet。

所以,如果你有被映射在/*和如下

request.getRequestDispatcher("/WEB-INF/jsp" + request.getPathInfo() + ".jsp").forward(request, response); 

那么你<c:redirect>将工作分派请求的控制器servlet。但是如果您没有这样的控制器,那么您应该使用<jsp:include>或将home.jsp转换为公共webcontent(其中您的index.jsp也是),并将其重定向到home.jsp


无关的问题,你的方式宣告了JSTL标签库不给我你正在做的事情以正确的方式或读取正确的教程一种强烈的感觉。我建议你看看我们的JSTL tag wiki

+0

哇!谢谢先生。我在想同样的观点,但我想确定这个事实。非常感谢 – 2011-02-03 20:00:25

0

您需要重定向到“/home.jsp”,而不仅仅是“/ home”。