<!DOCTYPE tiles-definitions PUBLIC "-
"http:>
<tiles-definitions>
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
org.apache.commons.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (8523356) exceeds the configured maximum (2097152)
at org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.<init>(FileUploadBase.java:914)2008-5-27 17:46:51 com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
警告: Could not find property [struts.valueStack]
2008-5-27 17:46:51 com.opensymphony.xwork2.util.logging.commons.CommonsLogger error
严重: the request was rejected because its size (8523356) exceeds the configured maximum (2097152)
2008-5-27 17:46:51 com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
警告: Could not find property [org.apache.catalina.jsp_file]
原因:上传文件大小超过预定大小,可以在struts.properties配置文件中设置struts.multipart.maxSize=XXX(XXX为文件大小)
8---配置了文件类型限制后,当传错误类型可以拦截不让用户上传该文件,可是跳转的页面却没有跳转到input配置的错误页面,而是返回
到了success正确页面。
严重: Content-Type not allowed: filedata "upload__5b01657_11a329d4dcf__8000_00000000.tmp" text/plain
《我的打印输出DEBUG语句内容:File:null FlieName:null type:null》即拦截类型成功了
java.lang.NullPointerException
at java.io.FileInputStream.<init>(FileInputStream.java:103)
at com.study.web.util.FileUploadUtil.uploadFile(FileUploadUtil.java:36)
at com.study.web.action.UploadFileAction.execute(UploadFileAction.java:58)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)。。。
2008-5-29 10:59:07 com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
警告: Could not find property [org.apache.catalina.jsp_file]
2008-5-29 10:59:07 com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
警告: Could not find property [struts]
2008-5-29 10:59:07 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Removing file filedata \tmp\upload__5b01657_11a329d4dcf__8000_00000000.tmp
原因及解决办法:在该文件上传Action中只配置了FileUploadInterceptor后缺少配置了defaultStack拦截器.
在ACTION中配置玩defaultStack拦截器后改错误消失。
9---struts.properties中全局配置文件大小,再使用默认FileUploadInterceptor拦截器时候能实现拦截的功能但是后台出现异常。
严重: Unable to parse request
org.apache.commons.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (380) exceeds the configured maximum (10)
at org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.<init>(FileUploadBase.java:914)
原因:未知。将全局配置中的限制大小去掉,再重新在ACTION中覆盖配置FileUploadInterceptor拦截器设置大小和文件类型限制,可消除异常。
10---多文件上传中,其中一个传被限制的文件如限制aplication/msword(即.doc)文件,允许传文本文件。然而当夹杂在一起传的时候,后台能截获类型错误不可传信息,但是
实际却还是上传成功。
严重: Content-Type not allowed: filedata "upload_4d958287_11a33e76ab9__8000_00000007.tmp" application/msword
file is :\tmp\upload_4d958287_11a33e76ab9__8000_00000006.tmp fileName:project.txt fileType:text/plain
file is :\tmp\upload_4d958287_11a33e76ab9__8000_00000007.tmp fileName:application base.doc fileType:application/msword
file is :\tmp\upload_4d958287_11a33e76ab9__8000_00000008.tmp fileName:zhongqi-bug.txt fileType:text/plain
原因:忘记了继承ActionSupport类。继承后异常消失。
11--文件上传异常,不能创建File文件
Cannot create type class java.io.File from value C:\Documents and Settings\admin\桌面\OrderReporterServiceImp.java - [unknown location]
原因:忘记了在form表单里将enctype设置成文件上传格式:enctype="multipart/form-data"
12--当使用限制文件类型和大小的时候抛出空指针异常
java.lang.NullPointerException
demo.struts2.action.ValidatFileUploadAction.execute(ValidatFileUploadAction.java:71)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
原因:在ACTION中配置了fileUpload拦截器后忘记了配置默认拦截器:defautlStack。注意当ACTION中配置自己的拦截器后需要显示配置默认
拦截器defaultStack
13--在国际化时候抛空指针异常:
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配置包
警告: No configuration found for the specified action: 'ShowMessage' in namespace: ''. Form action defaulting to 'action' attribute's literal value.
解决方法:
经过测试发现,是没有正确使用tag的原因,这种情况下,正确的写法应该是,<s:form name="login" method="post" action="login" >
您是否添加了action这个呢?