struts2 异常处理总结
1---:java .lang.NoClassDefFoundError: org/apache/struts2/dojo/views/jsp/ui/HeadTag
解决办法:原因缺少了dojo的JAR包,引入即可:struts2-dojo-plugin-2.1.2.jar
(
The "head" tag renders required JavaScript code to configure Dojo and is required in order to use any of the tags included in the Dojo plugin.
--------------------
If you are planning to nest tags from the Dojo plugin, make sure you set parseContent="false", otherwise each request made by the inner tags will be performed twice.
)
2---:Unable to load configuration. - bean - jar:file :/F:/Struts2/Struts2/WebRoot/WEB-INF/lib/struts2-core- 2.1.2.jar!/struts-default.xml:46:178
Caused by: Unable to load bean: type :org.apache.struts2.dispatcher.multipart.MultiPartRequest class :org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest - bean - jar:file :/F:/Struts2/Struts2/WebRoot/WEB-INF/lib/struts2-core-2.1.2.jar!/struts-default.xml:46:178
Caused by: java .lang.NoClassDefFoundError: org/apache/commons/fileupload/RequestContext
解决办法:缺少JAR包,引入commons-fileupload-1.2.1.jar,commons-io -1.3.2.jar即可
3---:No tag "datetimepicker" defined in tag library imported with prefix "s"
原因版本问题:缺少struts-dojo-plugin JAR包,以及HTML的,<HEAD></HEAD>中没有使用<s:head/>标签
If you're using Struts 2.1.x you're probably missing the> struts-dojo-plugin . Michaël's reference below applies to Struts 2.1.xonly. In the lasts versions (since 2.0.9 I guess), all AJAX are in dojo> plugin.
> > So you need to include <%@ taglib uri="/struts-dojo-tags" prefix="sx"%>
> > and <sx:head/>
> >( Temp1:
<sx:datetimepicker name="picker" />
Temp2:
<sx:datetimepicker type ="time" name="picker" /><br/>
Temp3:
<sx:datetimepicker value="%{'2008-06-08'}" name="picker" />
Temp4:
<sx:datetimepicker value="date" name="picker" />)
> > and call :<sx:datetimepicker .../>
4---:使用TILES框架
If you use the Tiles 2 plugin, check your tiles.xml file (s) to ensure they contain a DOCTYPE.
16:31:12,812 ERROR [jsp]:253 - Servlet.service() for servlet jsp threw exception
java .lang.NullPointerException at java .text.MessageFormat.applyPattern(MessageFormat.java :414)
at java .text.MessageFormat.<init>(MessageFormat.java :350)
at com.opensymphony.xwork2.DefaultTextProvider.getText(DefaultTextProvider.java :70)
原因:忘记了在struts.xml中配置国际化常量,或者在struts.properties中配置全局国际化常量 struts.custom.i18n.resources=globeMessage
14-- struts action的配置文件加载失败:
Unable to load configuration. - result - file :/D:/Java /apache-tomcat-5.5.20/webapps/mysts/WEB-INF/classes/test.xml:10:26
Caused by: No result type specified for result named 'error', perhaps the parent package does not specify the result type ? - result - file :/D:/Java /apache-tomcat-5.5.20/webapps/mysts/WEB-INF/classes/test.xml:10:26
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.buildResults(XmlConfigurationProvider.java :609)
原因:忘记了继承包struts-default
15-- struts action 配置文件注意事项:
1. 别忘记了继承struts-default默认配置包
2.如果配置命名空间,一定要以"/"开始,例如:namespace="/test"
3.每个模块struts action配置文件中都可以配置全局result,global-result 经测试不会冲突,STRTUS会智能寻找该Action请求的
模块STRUTS ACTION配置包