Hi Lance, Just curious, I implemented multipart request handler using Struts 1.2, ActionForm and Actoin class ( not using Fileter...) .
like: protected ActionForward executeAction( ActionMapping mapping , ActionForm form , HttpServletRequest request , HttpServletResponse response ) { ActionErrors errors = new ActionErrors() ; HttpSession session = request.getSession() ; String contentType = request.getContentType() ; if( contentType == null || !contentType.startsWith( "multipart/form- data" ) ) return null ; MultiFilesImportForm multiFilesImportForm = (MultiFilesImportForm) form ; Hashtable multiFormFileTable = multiFilesImportForm.getMultiFilesTable() ; ...... ** executeAction calls execute internally. My ActionForm ( called MultiFilesImportForm ) is like: public class MultiFilesImportForm extends ActionForm { public MultiFilesImportForm() { } public Hashtable getAllRequestTable() { return getMultipartRequestHandler().getAllElements() ; } public Hashtable getMultiFilesTable() { Hashtable fileElements = getMultipartRequestHandler().getFileElements() ; Hashtable stringElements = getMultiStringTable() ; for( Enumeration enumStrKey = stringElements.keys() ; enumStrKey. hasMoreElements() ; ) fileElements.remove( enumStrKey.nextElement() ) ; return fileElements ; } public Hashtable getMultiStringTable() { Hashtable multiStringTable = new Hashtable() ; Hashtable allRequestTable = getAllRequestTable() ; for( Enumeration enumKey = allRequestTable.keys() ; enumKey. hasMoreElements() ; ) { String key = (String) enumKey.nextElement() ; Object elem = allRequestTable.get( key ); if( elem instanceof String ) multiStringTable.put( key , elem ) ; } return multiStringTable ; } public ActionErrors validate( ActionMapping mapping , HttpServletRequest request ) { ....... Best Regards, trad-ex >Can someone tell me the best way to deal with multipart parameters in a >Filter without affecting struts? > >In my filter, request.getParameterMap() returns an empty map because the >multipart content has not yet been parsed. I had a look in the struts >code and saw references to a MultipartRequestWrapper and a >CommonsMultipartRequestHandler. From what I can see, the requestHandler >parses the request and calls MultipartRequestWrapper.setParameter(). > >So... in my filter I do the following: > >protected void doFilter(HttpServletRequest request, HttpServletResponse >response, FilterChain chain) throws IOException, ServletException { > boolean isMultipart = isMultipart(request); > Map parameterMap; > if (isMultipart) { > // wrap the request so that >CommonsMultipartRequestHandler.handleRequest() > // can call set parameter. the wrapped request is then passed >down the filter chain > request = new MultipartRequestWrapper(request); > MultipartRequestHandler multipartHandler = new >CommonsMultipartRequestHandler(); > ModuleConfig moduleConfig = (ModuleConfig) >servletContext.getAttribute(Globals.MODULE_KEY); > request.setAttribute(Globals.MODULE_KEY, moduleConfig); > multipartHandler.handleRequest(request); > request.removeAttribute(Globals.MODULE_KEY); > parameterMap = multipartHandler.getTextElements(); > } else { > parameterMap = request.getParameterMap(); > } > > // do some stuff with the parameters > > chain.doFilter(request, response); >} > >The problem now is that when I upload a file, struts thinks the file is >null. request.getParameter() works for normal text parameters on the >multipart form. >I have also tried parsing the request and sending the non-wrapped >request down the chain but struts does not re-parse the request if i do >this. > >I am using struts 1.3.5 > >Thanks, >Lance. > > >--------------------------------------------------------------------- >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]