在项目中使用到Struts2的dojo时,出现java.io.FileNotFoundException: Template /template/ajax/head.ftl not found. 有时出现.../text.ftl not found. 错误。
分析一下:
从strtus2.1.x开始,Struts2团队将dojo从核心包里面提取出来,成为一个struts2的插件struts2-dojo-plugin-*.jar,因此在jsp页面上,若要使用dojo的话,必须引入如下标签库:
<%@ taglib prefix="sx" uri="/struts-dojo-tags"%><sx:head />
当然,若要使用Struts2的标签库,还需引入<%@ taglib prefix="s" uri="/struts-tags"%/>标签库。
另外,Struts2的标签(无论是dojo或非dojo)均需要freeMarker模板文件*.ftl进行渲染和解释以生成Html页面,dojo或非dojo的标签库均配备一套自己的模板文件库,在jsp页面里,struts2根据各标签的theme来查找自己配置的相应模板文件*.ftl,若theme设置不对,则struts2就会从相应路径中找不到需要的ftl文件,就会报错../*.ftl not found.
当在jsp页面内,标签的主题(theme)若设置不正确,则会找不到相应的ftl文件。 比如下面代码:
<s:form method="post" validate="true" theme="xhtml">
<s:textfield label="Name" name="name" />
<s:password label="Password" name="password" />
<s:textfield label="Age" name="age" />
<ss:submit />
</s:form>
上述的theme定为xhtml,若是修改为theme="ajax",则在运行时jsp页面将不会被解析,提示.../text.ftl not found。 这是因为在struts2的核心包中没有template/ajax/text.ftl文件。
jsp文件中使用的标签是dojo的,就会根据theme的设置到与dojo配置的模板文件中去找,使用的标签为struts2的,就到与struts2配套的模板文件中去找。这样才能找得到自己需要的模板文件进行渲染。呵呵,经历了痛苦的探索之后,终于明白了个中原理。
分享到:
相关推荐
本文档资料适合java struts2 ajax dojo开发人员使用.
struts2-dojo-plugin-2.3.15.3.jar.zip
Apache Struts Copyright 2000-2011 The Apache Software Foundation This product includes software developed by The Apache Software Foundation (http://www.apache.org/). Dojo (http://dojotoolkit.org/). ...
Apache Struts Copyright 2000-2011 The Apache Software Foundation This product includes software developed by The Apache Software Foundation (http://www.apache.org/). Dojo (http://dojotoolkit.org/). ...
Apache Struts Copyright 2000-2007 The Apache Software Foundation This product includes software developed by The Apache Software Foundation (http://www.apache.org/). Dojo (http://dojotoolkit.org/). ...
Apache Struts Copyright 2000-2011 The Apache Software Foundation This product includes software developed by The Apache Software Foundation (http://www.apache.org/). Dojo (http://dojotoolkit.org/). ...
struts2-dojo 跨域时解决拒绝访问的问题
使用方便,无需安装配置, 下载置入dojo源码下的任意目录即可一键完成打包压缩. 该工具可自动分析HTML文件生成打包方案,自动排除没有用到的js文件,可将dojo压缩到数百K大小. 自带支持高亮、代码提示的profile编辑器,...
struts2-dojo-plugin-2.3.4 jar 日期控件的jar包 需要的自行下载
Struts Dojo 插件的例子 Struts Dojo 插件 的例子Struts Dojo 插件 的例子
Struts2的使用中出现的版本不符合或者缺少struts2-dojo-plugin-2.3.16的问题,大家可以下载使用。
struts2-dojo-plugin-2.1.0的jar包,可以再struts中使用dojo......
Addison.Wesley.Dojo.Using.the.Dojo.JavaScript.Library.to.Build.Ajax.Applications.Jun.2008.pdf
3、打开浏览器在地址栏输入:http://localhost:8080/Struts2Ajax/login.jsp后回车 4、如果一切正常,那么你会看“测试Ajax”按钮和Struts2的tabbedpanel标签 说明:Struts2天生成Spring整合的,所在“整容”之后,...
struts2+dojo ajax实现小例子,部署后可直接使用,可供学习和参考。
struts2-dojo-plugin-2.3.1.2.jar
commons-fileupload-1.2.1.jar//文件上传时用的,为了以后用到,最好加入 commons-io-1.3.2.jar//同上 commons-logging-1.0.4.jar freemarker-2.3.16.jar ...共8个包,将其复制到/Struts2/WebRoot/WEB-INF/lib下面
dojo-0.3.1-ajax
struts2-dojo-plugin-2.3.8