我在spring-app的servlet.xml中声明了这两个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点击。我相信我在这里遗漏了一些东西。
答案 0 :(得分:0)
怎么样
<a href="<c:url value="/apple.htm" />" > Apple</a>