﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-Hans 的流年-文章分类-Struts</title><link>http://www.blogjava.net/hansdyj/category/28745.html</link><description>Java
Flex
ActionScript
Ext</description><language>zh-cn</language><lastBuildDate>Fri, 18 Jan 2008 14:28:55 GMT</lastBuildDate><pubDate>Fri, 18 Jan 2008 14:28:55 GMT</pubDate><ttl>60</ttl><item><title>J2EE综合——Struts常见错误的全面汇总</title><link>http://www.blogjava.net/hansdyj/articles/176159.html</link><dc:creator>Hans Ding</dc:creator><author>Hans Ding</author><pubDate>Fri, 18 Jan 2008 04:17:00 GMT</pubDate><guid>http://www.blogjava.net/hansdyj/articles/176159.html</guid><wfw:comment>http://www.blogjava.net/hansdyj/comments/176159.html</wfw:comment><comments>http://www.blogjava.net/hansdyj/articles/176159.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/hansdyj/comments/commentRss/176159.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/hansdyj/services/trackbacks/176159.html</trackback:ping><description><![CDATA[<strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; 1、&#8220;No bean found under attribute key XXX&#8221;</strong>
<p>　　在struts-config.xml里定义了一个ActionForm，但type属性指定的类不存在，type属性的值应该是Form类的全名。或者是，在Action的定义中，name或attribute属性指定的ActionForm不存在。</p>
<p><br />
</p>
<p>　<strong>　2、&#8220;Cannot find bean XXX in any scope&#8221;</strong></p>
<p>　　在Action里一般会request.setAttribute()一些对象，然后在转向的jsp文件里(用tag或
request.getAttribute()方法)得到这些对象并显示出来。这个异常是说jsp要得到一个对象，但前面的Action里并没有将对象设
置到request(也可以是session、servletContext)里。</p>
<p>　　可能是名字错了，请检查jsp里的tag的一般是name属性，或getAttribute()方法的参数值;或者是Action逻辑有问题没有执行setAttribute()方法就先转向了。</p>
<p>　　还有另外一个可能，纯粹是jsp文件的问题，例如会指定一个id值，然后在循环里使用这个值作为name的值，如果这两个值不同，也会出现此异常。(都是一个道理，request里没有对应的对象。)</p>
<p><br />
</p>
<p>　<strong>　3、&#8220;Missing message for key "XXX"&#8221;</strong></p>
<p>　　缺少所需的资源，检查ApplicationResources.properties文件里是否有jsp文件里需要的资源，例如：</p>
<p>　　这行代码会找msg.name.prompt资源，如果AppliationResources.properties里没有这个资源就会出现
本异常。在使用多模块时，要注意在模块的struts-config-xxx.xml里指定要使用的资源文件名称，否则当然什么资源也找不到，这也是一个
很容易犯的错误。</p>
<p><br />
</p>
<p>　　<strong>4、&#8220;No getter method for property XXX of bean teacher&#8221;</strong></p>
<p>　　这条异常信息说得很明白，jsp里要取一个bean的属性出来，但这个bean并没有这个属性。你应该检查jsp中某个标签的property属性的值。例如下面代码中的cade应该改为code才对：</p>
<p><br />
</p>
<p>　<strong>　5、&#8220;Cannot find ActionMappings or ActionFormBeans collection&#8221;</strong></p>
<p>　　待解决。</p>
<p><br />
</p>
<p>　<strong>　6、&#8220;Cannot retrieve mapping for action XXX&#8221;</strong></p>
<p>　　在.jsp的</p>
<p>　　标签里指定action='/XXX'，但这个Action并未在struts-config.xml里设置过。</p>
<p><br />
</p>
<p>　　<strong>7、HTTP Status 404 - /xxx/xxx.jsp</strong></p>
<p>　　Forward的path属性指向的jsp页面不存在，请检查路径和模块，对于同一模块中的Action转向，path中不应包含模块名;模块间转向，记住使用contextRelative="true"。</p>
<p><br />
</p>
<p>　<strong>　8、没有任何异常信息，显示空白页面</strong></p>
<p>　　可能是Action里使用的forward与struts-config.xml里定义的forward名称不匹配。</p>
<p><br />
</p>
<p>　<strong>　9、&#8220;The element type "XXX" must be terminated by the matching end-tag "XXX".&#8221;</strong></p>
<p>　　这个是struts-config.xml文件的格式错误，仔细检查它是否是良构的xml文件，关于xml文件的格式这里就不赘述了。</p>
<p><br />
<span id="contentAdv">
<script language="JavaScript" src="http://www.ctocio.com.cn/ttfiles/ccimages/webservices_pip.js"></script>
</span></p>
<p>　<strong>　10、&#8220;Servlet.init() for servlet action threw exception&#8221;</strong></p>
<p>　　一般出现这种异常在后面会显示一个关于ActionServlet的异常堆栈信息，其中指出了异常具体出现在代码的哪一行。我曾经遇到的一次提示如下：</p>
<p>　　java.lang.NullPointerException</p>
<p>　　at org.apache.struts.action.ActionServlet.parseModuleConfigFile(ActionServlet.java:1003)</p>
<p>　　at org.apache.struts.action.ActionServlet.initModuleConfig(ActionServlet.java:955)</p>
<p>　　为解决问题，先下载struts的源码包，然后在ActionServlet.java的第1003行插入断点，并对各变量进行监视。很丢人，我竟然把struts-config.xml文件弄丢了，因此出现了上面的异常，应该是和CVS同步时不小心删除的。</p>
<p><br />
</p>
<p>　<strong>　11、&#8220;Resources not defined for Validator&#8221;</strong></p>
<p>　　这个是利用Validator插件做验证时可能出现的异常，这时你要检查validation.xml文件，看里面使用的资源是否确实有定义，form的名称是否正确，等等。</p>
<img src ="http://www.blogjava.net/hansdyj/aggbug/176159.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/hansdyj/" target="_blank">Hans Ding</a> 2008-01-18 12:17 <a href="http://www.blogjava.net/hansdyj/articles/176159.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>