我使用带有freemarker的spring作为模板引擎 . Freemarker允许使用Jsp Taglibs,例如,通过添加安全性
<#assign security=JspTaglibs["http://www.springframework.org/security/tags"] />
到模板,允许我使用的例子
<@security.authorize ifNotGranted="ROLE_ADMIN">
whatever
</@security.authorize>
但是,Spring / Freemarker找不到taglib,除非它们被添加到类路径中,所以我补充说
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-taglibs</artifactId>
<version>${spring.version}</version>
</dependency>
到我项目中的pom.xml .
但无论如何,无法找到标签!我必须将spring-security-taglibs.jar添加到WEB-INF / lib文件夹中,以便找到标签 .
有人知道为什么必须将jar显式添加到lib文件夹中吗?在我看来,tomcat为什么不找到它们?
编辑@ddekany
谢谢 . 如果未将spring-security-taglibs.jar复制到WEB-INF / lib目录中,则堆栈跟踪如下所示
No mapping defined for http://www.springframework.org/security/tags
The problematic instruction: ---------- ==> assignment:
security=JspTaglibs["http://www.springframework.org/security/tags"]
[on line 12, column 1 in home.ftl] in user-directive content.main
[on line 8, column 9 in home.ftl] in user-directive layout.global
[on line 2, column 1 in home.ftl]
---------- Java backtrace for programmers: ----------
freemarker.template.TemplateModelException:
No mapping defined for http://www.springframework.org/security/tags at
freemarker.ext.jsp.TaglibFactory.get(TaglibFactory.java:180) at
...
3 回答
您是否已将
JspSupportServlet
包含在here和here中[编辑]在仔细阅读你的帖子后,我建议你阅读"JSP.7.3.2"(以及之后的)JSP specification .
万一其他人遇到这个......
您需要添加 spring 支持文件,如此处所述(只是一些剪切和粘贴)http://static.springsource.org/spring-webflow/docs/2.2.x/reference/html/ch13s09.html .
然后添加一些依赖项:
假设您已完成其他所有工作,您现在应该能够将taglib添加到您的页面中 . 例如:
xmlns:sec = "http://www.springframework.org/security/tags"
<sec:authorize ifAllGranted = "USER_ROLE">
你好用户
</ sec:authorize>
*必须添加空格b / f 'sec'才能发布
使用此Maven依赖项:
org.springframework
和org.springframework.security
是具有不同版本号的不同框架 .