2023年12月8日发(作者:)

提示ortedClassVersionError: Bad version number

in .class file

Myeclipse 使用的JDK和Tomcat使用的JDK版本不一致

解决方法:

把它们的JDK版本改成一致步骤如下:

--> Preferences -->Java --> compiler中的compiler compliance

level对应的下拉菜单中选择JDK版本.

--> Preferences -->MyEclipse --> Servers -->Tomcat --> Tomcat

n.x -->JDK中的Tomcat JDK name下的下拉菜单中选择自身电脑上安装的JDK版本

1 、缺少文件上传JAR包

Unable to load bean

artRequest (jakarta) -

[unknown location]

这个问题是在使用Struts2想做一个上传文件的页面时候Tomcat报出来的错误,详细信息如下:

2007-7-19 21:34:09 rdWrapperValve

invoke

严重: e() for servlet jsp threw exception

eException: Unable to load bean

artRequest (jakarta) -

[unknown location]

问题描述:使用Struts2.0.6+Sitemesh2.2.1+Freemark2.3.8的过程中,装饰Action请求的结果页面不会有问题,但是如果装饰直接访问的JSP页面会出现如下错误:

java 代码

1. tException: Error applying decorator: null

解决方案:经过调试发现是FreeMarkerPageFilter的getLocale方法没有对invocation添加非空判断造成的,错误代码如下:

java 代码 1. protected Locale getLocale(ActionInvocation invocation, Configuration

configuration) {

2. if (ion() instanceof LocaleProvider) {

3. return ((LocaleProvider) ion()).getLocale();

4. } else {

5. return ale();

6. }

7. }

改正后的代码如下:

java 代码

1. protected Locale getLocale(ActionInvocation invocation, Configuration

configuration) {

2. if (invocation != null && ion() instanceof LocaleProvider) {

3. return ((LocaleProvider) ion()).getLocale();

4. } else {

5. return ale();

6. }

7. }

问题描述:使用Struts2.0.6+Sitemesh2.2.3,我有一个请求/customer/,其结果页面为WEB-INF/jsp/customer/,我希望使用main装饰器对返回结果进行装饰,如果配置如下:

xml 代码

1.

2. /WEB-INF/jsp/customer/tern>

3. decorator>

则无法成功进行装饰,如果配置如下:

xml 代码

1.

2. /*pattern>

3. decorator>

则可以成功进行装饰。

解决方案:经过调试发现,原来装饰器是根据请求的URI路径匹配需要装饰的页面的,而且此URI路径是相对于上下文路径的,因此针对上述需求正确的配置如下: xml 代码

1.

2. /customer/pattern>

3. decorator>

1---:sDefFoundError:

org/apache/struts2/dojo/views/jsp/ui/HeadTag

解决办法:原因缺少了dojo的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-

!/:46:178

Caused by: Unable to load bean:

type:artRequest

class:aMultiPartRequest

- bean

- jar:file:/F:/Struts2/Struts2/WebRoot/WEB-INF/lib/!/:46:178

Caused by: sDefFoundError:

org/apache/commons/fileupload/RequestContext

解决办法:缺少JAR包,引入,即可

3---:No tag "datetimepicker" defined in tag library imported with prefix

"s"

原因版本问题:缺少struts-dojo-plugin JAR包,以及HTML的,中没有使用标签

If you're using Struts 2.1.x you're probably missing

the> struts-dojo-plugin. Michaël's reference below applies to Struts

. 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 > >( Temp1:

Temp2:


Temp3:

Temp4:

)

> > and call :

4---:使用TILES框架

If you use the Tiles 2 plugin, check your file(s) to ensure

they contain a DOCTYPE.

Foundation//DTD Tiles Configuration 2.0//EN"

"/dtds/tiles-config_2_">

5---:struts2中不支持EL表达式 Convert EL expressions to OGNL

Struts2.1 tags do not allow evaluation of JSP EL within their

attributes.

Instead, Struts2 tags evaluate attribute values as OGNL. Allowing

both

expression languages within the same attribute opens major security

vulnerabilities.

6---文件上传过程中取不到文件名和文件类型,即都取到NULL

原因:假如页面中file的name=“a”则我们ACTION中设置String

aContentType,String aFileName;(此两个其实无所谓,要害是SET方法)

setA(File file)(){}; setAContentType(String

s){};setAFileName(String name){} 即格式如下:setXContentType()

setXFileName().X代表你给FILE取的NAME名字

必须和它相同,固定格式

7---严重: Unable to parse request

loadBase$SizeLimitExceededException: the request was rejected because its size (8523356) exceeds the

configured maximum (2097152)

at

loadBase$FileItemIteratorImpl.(:914)2008-5-27 17:46:51

sLogger warn

警告: Could not find property [tack]

2008-5-27 17:46:51

sLogger error

严重: the request was rejected because its size (8523356) exceeds the

configured maximum (2097152)

2008-5-27 17:46:51

sLogger warn

警告: Could not find property [_file]

原因:上传文件大小超过预定大小,可以在ties配置文件中设置e=XXX(XXX为文件大小)

8---配置了文件类型限制后,当传错误类型可以拦截不让用户上传该文件,可是跳转的页面却没有跳转到input配置的错误页面,而是返回

到了success正确页面。

严重: Content-Type not allowed: filedata

"upload__5b01657_11a329d4dcf__8000_" text/plain

《我的打印输出DEBUG语句内容:File:null FlieName:null type:null》即拦截类型成功了

interException

at putStream.(:103)

at

File(:36)

at

e(:58)

at 0(Native Method)。。。

2008-5-29 10:59:07

sLogger warn

警告: Could not find property [_file]

2008-5-29 10:59:07

sLogger warn

警告: Could not find property [struts]

2008-5-29 10:59:07

sLogger info

信息: Removing file filedata

tmpupload__5b01657_11a329d4dcf__8000_

原因及解决办法:在该文件上传Action中只配置了FileUploadInterceptor后缺少配置了defaultStack拦截器.

在ACTION中配置玩defaultStack拦截器后改错误消失。

ties中全局配置文件大小,再使用默认FileUploadInterceptor拦截器时候能实现拦截的功能但是后台出现异常。

严重: Unable to parse request

loadBase$SizeLimitExceededException: the request was rejected because its size (380) exceeds the

configured maximum (10)

at

loadBase$FileItemIteratorImpl.(:914)

原因:未知。将全局配置中的限制大小去掉,再重新在ACTION中覆盖配置FileUploadInterceptor拦截器设置大小和文件类型限制,可消除异常。

10---多文件上传中,其中一个传被限制的文件如限制aplication/msword(即.doc)文件,答应传文本文件。然而当夹杂在一起传的时候,后台能截获类型错误不可传信息,但是

实际却还是上传成功。

严重: Content-Type not allowed: filedata

"upload_4d958287_11a33e76ab9__8000_" application/msword

file

is :tmpupload_4d958287_11a33e76ab9__8000_ fileName: fileType:text/plain

file

is :tmpupload_4d958287_11a33e76ab9__8000_ fileName:application fileType:application/msword

file

is :tmpupload_4d958287_11a33e76ab9__8000_ fileName: fileType:text/plain

原因:忘记了继续ActionSupport类。继续后异常消失。

11--文件上传异常,不能创建File文件 Cannot create type class from value C:Documents and

Settingsadmin桌面 - [unknown location]

原因:忘记了在form表单里将enctype设置成文件上传格式:enctype="multipart/form-data"

12--当使用限制文件类型和大小的时候抛出空指针异常

interException

e(:71)

0(Native Method)

原因:在ACTION中配置了fileUpload拦截器后忘记了配置默认拦截器:defautlStack。注重当ACTION中配置自己的拦截器后需要显示配置默认

拦截器defaultStack

13--在国际化时候抛空指针异常:

16:31:12,812 ERROR [jsp]:253 - e() for servlet jsp

threw exception

interException at

attern(:414)

at eFormat.(:350)

at

t(:70)

原因:忘记了在中配置国际化常量,或者在ties中配置全局国际化常量 ces=globeMessage

14-- struts action的配置文件加载失败:

Unable to load configuration. - result -

file:/D:/Java/apache-tomcat-5.5.20/webapps/mysts/WEB-INF/classes/: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/:10:26

at

esults(:609)

原因:忘记了继续包struts-default

15-- struts action 配置文件注重事项:

1. 别忘记了继续struts-default默认配置包

2.假如配置命名空间,一定要以"/"开始,例如:namespace="/test"

3.每个模块struts action配置文件中都可以配置全局result,global-result 经测试不会冲突,STRTUS会智能寻找该Action请求的

模块STRUTS ACTION配置包

要害字: 警告: no configuration found for the specified action

警告: No configuration found for the specified action: 'ShowMessage' in

namespace: ''. Form action defaulting to 'action' attribute's literal

value.

解决方法:

经过测试发现,是没有正确使用tag的原因,这种情况下,正确的写法应该是,

您是否添加了action这个呢?

1---:sDefFoundError: org/apache/struts2/dojo/views/jsp/ui/HeadTag

解决办法:原因缺少了dojo的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- !/:46:178

Caused by: Unable to load bean:

type:artRequest

class:aMultiPartRequest - bean

- jar:file:/F:/Struts2/Struts2/WebRoot/WEB-INF/lib/!/:46:178

Caused by: sDefFoundError:

org/apache/commons/fileupload/RequestContext

解决办法:缺少JAR包,引入,即可

3---:No tag "datetimepicker" defined in tag library imported with prefix "s"

原因版本问题:缺少struts-dojo-plugin JAR包,以及HTML的,中没有使用标签

If you're using Struts 2.1.x you're probably missing

the> struts-dojo-plugin. Michaël's reference below applies to Struts . 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

> >( Temp1:

Temp2:


Temp3:

Temp4:

)

> > and call :

4---:使用TILES框架

If you use the Tiles 2 plugin, check your file(s) to ensure they contain

a DOCTYPE.

Foundation//DTD Tiles Configuration 2.0//EN"

"/dtds/tiles-config_2_">

5---:struts2中不支持EL表达式 Convert EL expressions to OGNL

Struts2.1 tags do not allow evaluation of JSP EL within their

attributes.

Instead, Struts2 tags evaluate attribute values as OGNL. Allowing

both expression languages within the same attribute opens major security

vulnerabilities.

6---文件上传过程中取不到文件名和文件类型,即都取到NULL

原因:如果页面中file的name=“a”则我们ACTION中设置String

aContentType,String aFileName;(此两个其实无所谓,关键是SET方法)

setA(File file)(){}; setAContentType(String

s){};setAFileName(String name){} 即格式如下:setXContentType()

setXFileName().X代表你给FILE取的NAME名字

必须和它相同,固定格式

7---严重: Unable to parse request

loadBase$SizeLimitExceededException: the request was rejected because its size (8523356) exceeds the

configured maximum (2097152)

at

loadBase$FileItemIteratorImpl.(:914)2008-5-27 17:46:51

sLogger warn

警告: Could not find property [tack]

2008-5-27 17:46:51

sLogger error

严重: the request was rejected because its size (8523356) exceeds the

configured maximum (2097152)

2008-5-27 17:46:51

sLogger warn

警告: Could not find property [_file]

原因:上传文件大小超过预定大小,可以在ties配置文件中设置e=XXX(XXX为文件大小)

8---配置了文件类型限制后,当传错误类型可以拦截不让用户上传该文件,可是跳转的页面却没有跳转到input配置的错误页面,而是返回

到了success正确页面。

严重: Content-Type not allowed: filedata

"upload__5b01657_11a329d4dcf__8000_" text/plain

《我的打印输出DEBUG语句内容:File:null FlieName:null type:null》即拦截类型成功了

interException

at putStream.(:103)

at

File(:36)

at

e(:58)

at 0(Native Method)。。。

2008-5-29 10:59:07

sLogger warn 警告: Could not find property [_file]

2008-5-29 10:59:07

sLogger warn

警告: Could not find property [struts]

2008-5-29 10:59:07

sLogger info

信息: Removing file filedata

tmpupload__5b01657_11a329d4dcf__8000_

原因及解决办法:在该文件上传Action中只配置了FileUploadInterceptor后缺少配置了defaultStack拦截器.

在ACTION中配置玩defaultStack拦截器后改错误消失。

ties中全局配置文件大小,再使用默认FileUploadInterceptor拦截器时候能实现拦截的功能但是后台出现异常。

严重: Unable to parse request

loadBase$SizeLimitExceededException: the request was rejected because its size (380) exceeds the

configured maximum (10)

at

loadBase$FileItemIteratorImpl.(:914)

原因:未知。将全局配置中的限制大小去掉,再重新在ACTION中覆盖配置FileUploadInterceptor拦截器设置大小和文件类型限制,可消除异常。

10---多文件上传中,其中一个传被限制的文件如限制aplication/msword(即.doc)文件,允许传文本文件。然而当夹杂在一起传的时候,后台能截获类型错误不可传信息,但是

实际却还是上传成功。

严重: Content-Type not allowed: filedata

"upload_4d958287_11a33e76ab9__8000_" application/msword

file

is :tmpupload_4d958287_11a33e76ab9__8000_ fileName: fileType:text/plain

file

is :tmpupload_4d958287_11a33e76ab9__8000_ fileName:application fileType:application/msword

file

is :tmpupload_4d958287_11a33e76ab9__8000_ fileName: fileType:text/plain

原因:忘记了继承ActionSupport类。继承后异常消失。

11--文件上传异常,不能创建File文件

Cannot create type class from value C:Documents and

Settingsadmin桌面 - [unknown location]

原因:忘记了在form表单里将enctype设置成文件上传格式:enctype="multipart/form-data"

12--当使用限制文件类型和大小的时候抛出空指针异常 interException

e(:71)

0(Native Method)

原因:在ACTION中配置了fileUpload拦截器后忘记了配置默认拦截器:defautlStack。注意当ACTION中配置自己的拦截器后需要显示配置默认

拦截器defaultStack

13--在国际化时候抛空指针异常:

16:31:12,812 ERROR [jsp]:253 - e() for servlet jsp

threw exception

interException at

attern(:414)

at eFormat.(:350)

at

t(:70)

原因:忘记了在中配置国际化常量,或者在ties中配置全局国际化常量 ces=globeMessage

14-- struts action的配置文件加载失败:

Unable to load configuration. - result -

file:/D:/Java/apache-tomcat-5.5.20/webapps/mysts/WEB-INF/classes/: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/:10:26

at

esults(:609)

原因:忘记了继承包struts-default

15-- struts action 配置文件注意事项:

1. 别忘记了继承struts-default默认配置包

2.如果配置命名空间,一定要以"/"开始,例如:namespace="/test"

3.每个模块struts action配置文件中都可以配置全局result,global-result 经测试不会冲突,STRTUS会智能寻找该Action请求的

模块STRUTS ACTION配置包

Servlet异常处理xml 代码 在中配置

Xml代码

1.

2. 404

3.

4.

5.

6.

7. interException

8.

9.

Struts的异常处理机制,在配置局部异常和全局异常

Xml代码

1.

2.

3.

4.

5.

6.

7.

8.

9. airticket/

10.

11. 12.

13.

3)编写一个Action 异常基类,子类继承而获得异常处理功能

Java代码

1. public abstract class ErrorBaseAction extends Action{

2.

3. public final ActionForward execute(ActionMapping mapping,

4. ActionForm form,

5. HttpServletRequest request,

6. HttpServletResponse response)

7. throws IOException, ServletException {

8. try{

9. return doExecute(mapping,form,request,response);

10. }catch(Exception ex){

11. return doException(ex,mapping,form,request,response);

12. }

13. }

14.

15. public ActionForward doException(Exception ex,

16. ActionMapping mapping,

17. ActionForm form,

18. HttpServletRequest request,

19. HttpServletResponse response)

20. throws IOException, ServletException {

21. // 异常处理

22. return rward("XXX");//返回页面

23. } 24.

25. public abstract ActionForward doExecute(ActionMapping mapping,

26. ActionForm form,

27. HttpServletRequest request,

28. HttpServletResponse response)

29. throws IOException, ServletException;

30.

31.}