第一步:在web.XML配置interMedia的filter
<filter>
<filter-name>interMediaFilter</filter-name>
<filter-class>Oracle.ord.im.OrdMultipartFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>interMediaFilter</filter-name>
<url-pattern>/ord/*</url-pattern>
</filter-mapping>
第二步:定義自己的MultipartDecoderFilter
仿照tapestry的MultipartDecoderFilter,寫自己的MultipartDecoderFilter(例如類名為org.MYMultipartDecoderFilter),自己寫的filter和tapestry相比主要是判斷request是否已被包裝,如果被包裝了就直接繼續處理(見下列代碼的if-else部分)
public void service(HttpServletRequest request,
HttpServletResponse response, ServletRequestServicer servicer)
throws IOException, ServletException ...{
String contentType = request.getContentType();
// contentType is occasionally null in testing. The browser tacks on additional
// information onto the contentType to indicate where the boundarIEs are in
// the stream.
boolean encoded = contentType != null
&& contentType.startsWith("multipart/form-data");
try ...{
//HttpServletRequest newRequest = encoded ? _decoder.decode(request) : request;
HttpServletRequest newRequest = null;
if (request instanceof HttpServletRequestWrapper) ...{
newRequest = request;
} else ...{
newRequest = encoded ? _decoder.decode(request) : request;
}
servicer.service(newRequest, response);
} finally ...{
if (encoded)
_decoder.cleanup();
// System.out.println("ttt");
}
}
在hivemodul中配置使用:
<implementation service-id="tapestry.multipart.ServletMultipartDecoderFilter">
IdentifIEs upload requests and passes them to the MultipartDecoder service for decoding.
<invoke-factory>
<construct class="org.MyMultipartDecoderFilter">
<set-service property="decoder" service-id="tapestry.multipart.ServletMultipartDecoder"/>
</construct>
</invoke-factory>
</implementation>
第三步:開始處理
頁面中注入屬性:
<inject property="requestGlobals" object="service:tapestry.globals.RequestGlobals" />
Html中使用表單的文件上傳元素(input type="file" name="upload"/>)或upload組件
在頁面類中即可得到interMedia類型的上傳文件:
RequestGlobals obj = this.getRequestGlobals();
OrdMultipartWrapper obj1 = (OrdMultipartWrapper) obj.getRequest();
OrdHttpUploadFile[] files = obj1 .getFileParameterValues("upload");