2012-07-08 70 views
0

上的鏈接時,我有我的彈簧應用程序的servlet.xml中宣佈的2種豆:錯誤404點擊一個jsp頁面

<bean name="/apple.htm" class="controller.AppleController"/> 

<bean name="/secure/banana.htm" class="controller.BananaController"/> 

這裏是香蕉控制器:

public class BananaController implements Controller { 

    protected final Log logger = LogFactory.getLog(getClass()); 

    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) 
      throws ServletException, IOException { 
     logger.info("returning contact view"); 
     return new ModelAndView("/banana"); 
    } 

} 

這裏是AppleController

public class AppleController implements Controller { 

    protected final Log logger = LogFactory.getLog(getClass()); 

    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) 
      throws ServletException, IOException { 
     logger.info("returning contact view"); 
     return new ModelAndView("/apple"); 
    } 

} 

這裏是Apple.jsp(Banana.jsp是相似的):

<%@ include file="/WEB-INF/pages/include.jsp" %> 
<html> 
<body> 
    <h1>Test</h1> 
    <%@ include file="/WEB-INF/pages/menu.jsp" %> 
    <h2>Apple</h2> 
    <p> 
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ac mauris ante. 
    </p> 

</body> 
</html> 

這裏是引入了menu.jsp:

<a href="<c:url value="apple.htm" />" > Apple</a> 
<a href="<c:url value="secure/banana.htm" />" > Banana</a> 
<a href="<c:url value="/j_spring_security_logout" />" > Logout</a> 

的問題是,一旦我登錄,我可以訪問banana.htm,不過呢,如果我回去的「蘋果」頁面,它會嘗試訪問secure/apple.htm頁面,因爲我已經位於/ secure文件夾中。

我知道../apple.htm會正確重定向,但沒有任何信息告訴我該鏈接只能從banana.htm中點擊。我相信我在這裏失去了一些東西。

回答

0

<a href="<c:url value="/apple.htm" />" > Apple</a>