Thomson-Blog ( 学习,学习,再学习;努力,努力,再努力。)
在学习的路上不断成长,成功之路就在脚下。
    1、“No bean found under attribute key XXX”

  在struts-config.xml里定义了一个ActionForm,但type属性指定的类不存在,type属性的值应该是Form类的全名。或者是,在Action的定义中,name或attribute属性指定的ActionForm不存在。

  2、“Cannot find bean XXX in any scope”

  在Action里一般会request.setAttribute()一些对象,然后在转向的jsp文件里(用tag或request.getAttribute()方法)得到这些对象并显示出来。这个异常是说jsp要得到一个对象,但前面的Action里并没有将对象设置到request(也可以是session、servletContext)里。

  可能是名字错了,请检查jsp里的tag的一般是name属性,或getAttribute()方法的参数值;或者是Action逻辑有问题没有执行setAttribute()方法就先转向了。

  还有另外一个可能,纯粹是jsp文件的问题,例如会指定一个id值,然后在循环里使用这个值作为name的值,如果这两个值不同,也会出现此异常。(都是一个道理,request里没有对应的对象。)

  3、“Missing message for key "XXX"”

  缺少所需的资源,检查ApplicationResources.properties文件里是否有jsp文件里需要的资源,例如:

  这行代码会找msg.name.prompt资源,如果AppliationResources.properties里没有这个资源就会出现本异常。在使用多模块时,要注意在模块的struts-config-xxx.xml里指定要使用的资源文件名称,否则当然什么资源也找不到,这也是一个很容易犯的错误。

  4、“No getter method for property XXX of bean teacher”

  这条异常信息说得很明白,jsp里要取一个bean的属性出来,但这个bean并没有这个属性。你应该检查jsp中某个标签的property属性的值。例如下面代码中的cade应该改为code才对:

  5、“Cannot find ActionMappings or ActionFormBeans collection”
错误信息 javax.servlet.jsp.JspException: Cannot find ActionMappings or ActionformBeans collection
可能原因
lEither the <servlet> tags for the Struts action servlet or the <servlet-mapping> tags for the .do extension mapping or both not present in the web.xml file. I saw a case where the web.xml file had no elements other than the root element and so this error was occurring.
lTypos or spelling errors in the struts-config.xml can lead to this error message. For example, missing a slash ("/") on a closing tag can have this effect.
lAnother element that must be present in the web.xml file is the load-on-startup element. This can be either an empty tag or can have an integer specified that indicates the priority of executing the associated servlet. The higher the number in the load-on-startup tags, the lower its priority.

  6、“Cannot retrieve mapping for action XXX”

  在.jsp的标签里指定action='/XXX',但这个Action并未在struts-config.xml里设置过。或没有找到匹配的action,例如在JSP文件中使用 <html:form action="Login.do".将表单提交给Login.do处理,如果出现上述异常,请查看struts-config.xml中的定义部分,有时可能是打错了字符或者是某些不符合规则,可以使用struts console工具来检查。

  7、HTTP Status 404 - /xxx/xxx.jsp

  Forward的path属性指向的jsp页面不存在,请检查路径和模块,对于同一模块中的Action转向,path中不应包含模块名;模块间转向,记住使用contextRelative="true"。

  8、没有任何异常信息,显示空白页面

  可能是Action里使用的forward与struts-config.xml里定义的forward名称不匹配。

  9、“The element type "XXX" must be terminated by the matching end-tag "XXX".”

  这个是struts-config.xml文件的格式错误,仔细检查它是否是良构的xml文件,关于xml文件的格式这里就不赘述了。

  10、“Servlet.init() for servlet action threw exception”

  一般出现这种异常在后面会显示一个关于ActionServlet的异常堆栈信息,其中指出了异常具体出现在代码的哪一行。我曾经遇到的一次提示如下:

  java.lang.NullPointerException

  at org.apache.struts.action.ActionServlet.parseModuleConfigFile(ActionServlet.java:1003)

  at org.apache.struts.action.ActionServlet.initModuleConfig(ActionServlet.java:955)

  为解决问题,先下载struts的源码包,然后在ActionServlet.java的第1003行插入断点,并对各变量进行监视。很丢人,我竟然把struts-config.xml文件弄丢了,因此出现了上面的异常,应该是和CVS同步时不小心删除的。

  11、“Resources not defined for Validator”

  这个是利用Validator插件做验证时可能出现的异常,这时你要检查validation.xml文件,看里面使用的资源是否确实有定义,form的名称是否正确,等等。

        12、No action instance for path /xxxx could be created 

      特别提示:因为有很多中情况会导致这个错误的发生,所以推荐大家调高你的web服务器的日志/调试级别,这样可以从更多的信息中看到潜在的、在试图创建action类时发生的错误,这个action类你已经在struts-config.xml中设置了关联(即添加了<action>标签)。
在struts-config.xml中通过action标签的class属性指定的action类不能被找到有很多种原因,例如:
定位编译后的.class文件失败。Failure to place compiled .class file for the action in the classpath (在web开发中,class的的位置在r WEB-INF/classes,所以你的action class必须要在这个目录下。例如你的action类位于WEB-INF/classes/action/Login.class,那么在struts-config.xml中设置action的属性type时就是action.Login).
拼写错误,这个也时有发生,并且不易找到,特别注意第一个字母的大小写和包的名称。
 
在struts-config.xml中指定的action类没有继承自Stuts的Action类,或者你自定义的Action类没有继承自Struts提供的Action类。

你的action类必须继承自Struts提供的Action类。
你的classpath的问题。例如web server没有发现你的资源文件,资源文件必须在WEB-INF/classes/目录下。 
Problem in struts-config.xml file with action mapping. 
Problem with data-sources.xml file.

13、org.apache.jasper.JasperException: Cannot retrieve definition for form bean null

      这个异常是因为Struts根据struts-config.xml中的mapping没有找到action期望的form bean。大部分的情况可能是因为在form-bean中设置的name属性和action中设置的name属性不匹配所致。换句话说,actionform都应该各自有一个name属性,并且要精确匹配,包括大小写。这个错误当没有name属性和action关联时也会发生,如果没有在action中指定name属性,那么就没有name属性和action相关联。当然当action制作某些控制时,譬如根据参数值跳转到相应的jsp页面,而不是处理表单数据,这是就不用name属性,这也是action的使用方法之一。


 14、javax.servlet.jsp.JspException: Exception creating bean of class org.apache.struts.action.Actionform: {1}
可能原因
lInstantiating Struts-provided Actionform class directly instead of instantiating a class derived off Actionform. This might occur implicitly if you specify that a form-bean is this Struts Actionform class rather than specifying a child of this class for the form-bean.
lNot associating an Actionform-descended class with an action can also lead to this error.

15、NullPointerException at ... RequestUtils.forwardURL
错误信息 java.lang.NullPointerException at org.apache.struts.util.RequestUtils.forwardURL (RequestUtils.java:1223)
可能原因
lMissing path attribute in the forward subelement of the action element in struts-config.xml
相关链接
16、Cannot find bean org.apache.struts.taglib.html.BEAN in any scope
错误信息 javax.servlet.jsp.JspException: Cannot find bean org.apache.struts.taglib.html.BEAN in any scope
可能原因
lTrying to use Struts form subelement tags outside of the Struts' form tag.
相关链接
lUsing form subelements outside of a form tag http://forum.java.sun.com/thread.jsp?thread=337537&forum=4&message=1384153  
  
17、Cannot find message resources under key org.apache.struts.action.MESSAGE
错误信息 Cannot find message resources under key org.apache.struts.action.MESSAGE
可能原因
lExplicitly trying to use message resources that are not available (such as ApplicationResources.properties not available
lImplicitly trying to use message resources that are not available (such as using empty html:options tag instead of specifying the options in its body -- this assumes options are specified in ApplicationResources.properties file)
lXML parser issues -- too many, too few, incorrect/incompatible versions

18、No input attribute for mapping path /loginAction
错误信息 No input attribute for mapping path /xxxxAction
可能原因
lNo input attribute in action mapping in struts-config.xml file for the action with the name specified in the error message. An input attribute is not required if form validation is not performed (either because the validate attribute is set to false or because the validation method in the relevant form class is not implemented. The input attribute specifies the page leading to this action because that page is used to display error messages from the form validation.

19、Strange Output Characters (页面乱码)
错误信息 Strange and seemingly random characters in HTML and on screen, but not in original JSP or servlet.
可能原因
lRegular HTML form tags intermixed incorrectly with Struts html:form tags.
HTML标签与Struts标签不正确的混合使用
lEncoding style used does not support characters used in page.
使用了JSP页面不支持的编码

20、"Document contained no data" or no data rendered on page (空白页面)
错误信息
l"Document contained no data" in Netscape (在Netscape中显示“文件中无数据”)
lNo data rendered (completely empty) page in Microsoft Internet Explorer(在IE中为空白页面,无任何显示信息)
可能原因
lEmploying a descendent of the Action class that does not implement the perform() method while using the Struts 1.0 libraries. Struts 1.1 Action child classes started using execute() rather than perform(), but is backwards compatible and supports the perform() method. However, if you write an Action-descended class for Struts 1.1 with an execute() method and try to run it in Struts 1.0, you will get this "Document contained no data" error message in Netscape or a completely empty (no HTML whatsoever) page rendered in Microsoft Internet Explorer.
l用Struts1.1写的应用在struts1.0环境中运行时,可能出现此问题。

其它错误信息
编译JSP文件时出现错误:
java.lang.NullPointerException
error:org.apache.jasper.JasperException: Error compiling \JSPs\security\appUserCreate.jsp
可能原因:
JSP页面中的Struts标记有语法错误。
例如:<bean:message key=”button.submit”> 错误原因:右边的括号前缺少斜杠“/”
正确的为:<bean:message key=”button.submit”/>

不同语言资源文件中的Key不匹配。

posted on 2008-07-15 09:18  Thomson-Blog  阅读(877)  评论(0编辑  收藏  举报