在我的GAE项目中使用SiteMesh时遇到了两个问题,现将解决方法整理如下:
一、 NoClassDefFoundError异常
在GAE中直接使用SiteMesh会抛如下异常:
Error for /
java.lang.NoClassDefFoundError: javax.naming.InitialContext is a restricted class. Please see the Google App Engine developer's guide for more details.
at com.google.apphosting.runtime.security.shared.stub.javax.naming.InitialContext.<clinit>(InitialContext.java)
at com.opensymphony.module.sitemesh.Factory.getEnvEntry(Factory.java:91)
……
针对这个问题,我在网上找到了三个办法:
1、 修改com.opensymphony.module.sitemesh.Factory. getEnvEntry()方法,将catch(Exception e)改成catch(Trowable e)即可。
2、 同样修改上面的方法,直接返回缺省值
3、 下载最新的2.4.2版本,地址是:https://sitemesh.dev.java.net/servlets/ProjectDocumentList?folderID=11231&expandFolder=11231&folderID=11231
建议选择第一种或第三种方法解决。
二、 Excludes无效
在decorators.xml配置的excludes标签无效,里面的页面仍然被装饰了。在网上搜到一个小技巧解决之,如下:
<decorator name="none">
<pattern>/excludes/*</pattern>
<pattern>/excludes.jsp</pattern>
</decorator>