On 19/04/2010 17:06, Ken Bowen wrote: > Using Tomcat 6.0.18 (to be 6.0.26) and Google App Engine, for parallel > development (different db tech) > > Short form: I need to accept a file upload in a servlet, do some > computations on the upload, and then transition to a JSP with some data > resulting from the computations. I'm having some trouble with the > transition at the end. I need either to make the current code work or > find an > alternate way to achieve the goal. > > Long form. Here's the html for file upload (vanilla): > > <form name="csvUploadForm" action="csvfileupload" method="post" > enctype="multipart/form-data"> > File:<input type="file" name="csvfile2upload"><br></br> > <input type="submit" name="Submit" value="Upload CSV File" > onclick="uploadCSVFile();return false;"> > </form> > > Here's the servlet mapping for the receiving/processing servlet: > > <servlet-mapping> > <servlet-name>CSVFileUpload</servlet-name> > <url-pattern>/csvfileupload/*</url-pattern> > </servlet-mapping>
Why use a wildcard instead of an absolute/explicit path, in both the action attribute and in the url-pattern? > The CSVFileUpload servlet doPost method uses > org.apache.commons.fileupload.servlet.ServletFileUpload; > to accept and process the upload, and puts the resulting data into the > db. If I don't care about duplicates or partial matches, > this works fine; at the end of the servlet processing, I execute > response.sendRedirect("/myStartPage.jsp"); > -- where response is the doPost's HttpServletResponse. > > Now I need to deal with partial matches between incoming data from the > upload, and information already in the db. Specifically, > I need to interact with the user to determine how to resolve the > ambiguities. I /thought/ I could create a bean with the necessary computed > info, use setAttribute to attach the bean to request (the doPost's > HttpServletRequest), and then forward to a JSP with code like this: > > String nextJSP = "/nextPage.jsp"; > RequestDispatcher dispatcher = > getServletContext().getRequestDispatcher(nextJSP); > dispatcher.forward(request, response); /myStartPage.jsp or /nextPage.jsp? When does the redirect occur and when does the forward occur, it's not entirely clear. > Unfortunately, I'm running into the following errors showing in the log: > > WARNING: Nested in javax.servlet.ServletException: > org.apache.commons.fileupload.FileUploadBase$InvalidContentTypeException: the > request doesn't contain a multipart/form-data or multipart/mixed stream, > content type header is null: > org.apache.commons.fileupload.FileUploadBase$InvalidContentTypeException: the > request doesn't contain a multipart/form-data or multipart/mixed stream, > content type header is null > at > org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.<init>(FileUploadBase.java:885) > > at > org.apache.commons.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:331) > > at > org.apache.commons.fileupload.servlet.ServletFileUpload.getItemIterator(ServletFileUpload.java:148) > > at > com.formrunner.servlets.CSVFileUploadServlet.doPost(CSVFileUploadServlet.java:53) > > at > com.formrunner.servlets.CSVFileUploadServlet.doGet(CSVFileUploadServlet.java:29) What's at CSVFileUploadServlet.java:53? > The browser actually displays the nextPage.jsp page. However, if one > then clicks any navigation button, you get a version of the warning > above showing in the browser. So you're catching the exception before executing the forward? > I'm assuming that the CSVFileUpload servlet processing of the upload has > stripped the request; hence the errors. I'm not sure I concur, it seems a little unclear as to what is really happening at this point. p > My goal is to get from the CSVFileUpload servlet to the nextPage.jsp > with the "partialMatch" data in hand. In the normal use case, this > will only be a couple of text lines. However, at the extreme it could > be hundreds of lines of mismatches. I really don't care how I > accomplish the transition to nextPage.jsp, so if there's a better way > than what I'm attempting here, please let me know. > {Anything written on the web would be great.} [I assume that I could > store the "partialMatch" data in the db under some appropriate key, get > to nextPage using response.sendRedirect, and then retrieve the info, but > that seems like more of a hack than ought to be necessary here.] > > Thanks in advance, > Ken > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org > For additional commands, e-mail: users-h...@tomcat.apache.org >
signature.asc
Description: OpenPGP digital signature