在struts.xml里引用拦截器,当上传文件超过一定大小的时候,在页面给出提示。在Myeclipse的控制台有错误信息,但是在页面没有任何提示。
1、struts.xml配置如下:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration       2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">

<struts>
<constant name="struts.custom.i18n.resources" value="message"></constant>
 <constant name="struts.multipart.maxSize" value="1008357"/>
 <constant name="struts.i18n.encoding" value="gbk"></constant>
 
<package name="exportExcel" extends="struts-default">
        
        <!--  合并万号段  -->
     <action name="upload*" class="com.huawei.parseNumSec.ParseNumSecAction" method="{1}">   
            <result name="input">/WEB-INF/parseNumSec/upload.jsp</result>
            <result name="success">/WEB-INF/parseNumSec/upload.jsp</result>
            
   <interceptor-ref name="fileUpload">
             <!-- 配置允许上传的文件类型 -->
              <param name="allowedTypes">application/vnd.ms-excel</param>
             <!-- 配置允许上传的文件大小 单位字节-->
              <param name="maximumSize">108357</param> 
              <param name="savePath">/upload</param>  
            </interceptor-ref>
            <interceptor-ref name="defaultStack"/> 
        </action>   
      </package>
</struts>    2、引用的国际化文件/getExcel/src/message.properties:
struts.messages.error.content.type.not.allowed=上传文件类型不允许,请重试!
struts.messages.error.file.too.large=上传文件过大,请重试!
3、upload.jsp:<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>My JSP 'upload.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript">
<%-- 动态添加和删除“浏览”按钮  --%>
        function AddMore()
        {   
            var more = document.getElementById("addFile");   
            var br = document.createElement("br");   
            var input = document.createElement("input");   
            var button = document.createElement("input");   
               
            input.type = "file";   
            input.name = "file";   
               
            button.type = "button";   
            button.value = "删除";   
               
            more.appendChild(br);   
            more.appendChild(input);   
            more.appendChild(button);   
               
            button.onclick = function(){   
            more.removeChild(br);   
            more.removeChild(input);   
            more.removeChild(button);   
            };    
        }
    </script>   
  </head>
  <body>   
  <table align="center" width="50%">
      <tr>
        <td><s:fielderror cssStyle="color:red"></s:fielderror></td>
      </tr>  
  </table>
    <!-- 上传文件表单定义 -->   
    <s:form action="uploadexecute" method="post" enctype="multipart/form-data" theme="simple">
       <table border="0" width="50%">   
        <tr>   
            <td colspan="2" align="center">号段汇总</td>   
        </tr>   
        <tr>   
            <td valign="top">附件:</td>   
            <td id="addFile">   
           <s:file name="file" label="文件"></s:file>   <input type="button" value="增加附件" onclick="AddMore()"/> 
            </td>   
        </tr>   
        <tr>   
            <td colspan="2" align="center">   
            <s:submit value="提交" onclick="checkFiles()"></s:submit></td>   
        </tr>   
    </table>       
    </s:form>   
    </body>   
</html>
4、在Myeclipse的控制台有错误信息:警告: Unable to parse request
org.apache.commons.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (8694752) exceeds the configured maximum (1008356)
at org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.<init>(FileUploadBase.java:937)
at org.apache.commons.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:331)
at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:351)
at org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest.parseRequest(JakartaMultiPartRequest.java:151)
at org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest.processUpload(JakartaMultiPartRequest.java:90)
at org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest.parse(JakartaMultiPartRequest.java:80)
at org.apache.struts2.dispatcher.multipart.MultiPartRequestWrapper.<init>(MultiPartRequestWrapper.java:75)
at org.apache.struts2.dispatcher.Dispatcher.wrapRequest(Dispatcher.java:740)
at org.apache.struts2.dispatcher.ng.PrepareOperations.wrapRequest(PrepareOperations.java:131)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:83)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Thread.java:595)
2012-4-19 16:45:12 com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
警告: the request was rejected because its size (8694752) exceeds the configured maximum (1008356)
2012-4-19 16:45:12 com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
警告: the request was rejected because its size (8694752) exceeds the configured maximum (1008356)
但是在页面没有任何提示,请问这是怎么回事啊?多谢!