Mark,
On 4/23/24 13:42, Mark Foley wrote:
I'm back with a related issue.
I was able to get the java class jakarta.servlet.annotation.MultipartConfig
working back last November by adding the <servlet> definition shown in the
included message below to my WEB-INF/web.xml file.
Now I need to add another program to the system that does file uploads. I
created another <server> definition in WEB-INF/web.xml following the original:
<servlet>
<servlet-name>uploadfile</servlet-name>
<jsp-file>/1099R-Etrans.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>/1099R-Etrans.jsp</url-pattern>
</servlet-mapping>
That didn't work so well. Now, any and all programs using the fileupload
function launches this 2nd program 1099R-Etrans.jsp. It appears that this
second <servlet> definition replaces the first. Of course, I need to have the
ability for more than one program in the system able to do file uploads.
How can I configure multiple JSP programs to all have file uploading enabled and
launched by the correspoding requesting program?
Can you post both <servlet> definitions and the <servlet-mapping>s for
each of them?
It's still yucky to use a JSP to do this IMHO.
-chris
On Thu Nov 16 14:36:21 2023 Christopher Schultz <ch...@christopherschultz.net>
wrote:
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>/schDistImportResults.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>/schDistImportResults.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
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org