我在我的 spring-app 的 servlet.xml 中声明了这 2 个 bean:
<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,但是,如果我回到“apple”页面,它会尝试访问secure/apple.htm页面,因为我已经找到了在 /secure 文件夹中。
我知道../apple.htm 会正确重定向,但没有什么告诉我该链接只能从banana.htm 中单击。我确定我在这里遗漏了一些东西。