Mark,

Apologies for not replying earlier; looks like you have made good progress. See below.

On 11/14/23 12:19, Mark Foley wrote:
Anyway, enough griping! I have gotten it partially working thanks to your
suggested link, and particulary you suggestion to put the servlet info in
web.xml.  I've put the following in WEB-INF/web.xml:

<servlet>
   <servlet-name>uploadfile</servlet-name>
     <jsp-file>/schDistImportResultsX.jsp</jsp-file>
     <multipart-config>
       <location>/tmp</location>
       <max-file-size>20848820</max-file-size>
       <max-request-size>418018841</max-request-size>
       <file-size-threshold>1048576</file-size-threshold>
     </multipart-config>
</servlet>
<servlet-mapping>
   <servlet-name>uploadfile</servlet-name>
   <url-pattern>/schDistImportResultsX.jsp</url-pattern>
</servlet-mapping>

I've only changed the <jsp-file> and <url-pattern> tags above. The others are
as monkey-typed from your link example. I'll research the other parameters
later.

My jsp code is now:

<%@ page import="javax.servlet.annotation.MultipartConfig.*" %>

Nope, not for Tomcat 10. You need to use the jakarta package names. Besides, you don't need the MultipartConfig in your code, anyway.

You need /either/ an annotation (dicey in JSP code) /or/ an XML config, so the XML should be sufficient. (But you should switch to a proper servlet. DO IT! :)

if((contentType != null) && contentType.startsWith("multipart/form-data;"))
{
     InputStream inp = null;
     DataInputStream ins = null;

     Part fileUpload = request.getPart("taxResults");

     if(fileUpload != null)
     {
         inp = fileUpload.getInputStream();
         ins = new DataInputStream(inp);
     }
while ((inp != null) && (ins.available() != 0))
{
     String  transaction = ins.readLine();
     out.println("<br/>" + transaction);
}

ins.close();
inp.close();

I would use try-with-resources like this:

try (InputStream in = , DataInputStream ins = ...) {
}

Since you have no try/catch, your code can leak file handles and stuff like that. Yuck. With try-with-resources, you don't even need the calls to InputStream.close.

This actually worked!!!! I will experiment with it more and may be back with
more questions (e.g. do I really need the web.xml? Could I not do:
"inp = fileUpload.getInputStream(mypath);"). But ... maybe later.

Vielen Dank!!! --Mark

Na klar

-chris

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to