javax.naming.NameNotFoundException
I'm running Tomcat 8.5.11. I have a hopefully small problem. I have a webapp directory: $CATALINA_HOME/webapps/myapp/. In that directory I have WEB-INF/web.xml with: connURL jdbc:mysql://localhost/members? java.lang.String In this example, the env-entry is just part of an SQL connection string I want to snag. In a browser, going to: /myapp/index.jsp works fine with WEB-INF as shown above. What I want to do is put all of this in a sub-directory: $CATALINA_HOME/webapps/myapp/subapp/ and access it on my browser as /myapp/subapp/index.jsp. When I do that -- no changes to anything -- I get the error: javax.servlet.ServletException: javax.naming.NameNotFoundException: Name [connURL] is not bound in this Context. Unable to find [connURL]. Here is the jsp code: Context ctx = new javax.naming.InitialContext(); Context env = (Context) ctx.lookup("java:comp/env"); String _dbURL = (String) env.lookup("connURL")); Clearly, the error has something to do with the extra subdirectory level. Also, when I do getServletContext().getRealPath("") in my jsp program it only returns "/srv/tomcat/webapps/myapp", not .../myapp/subapp How do I fix this so env.lookup("") find my env-entry? How do I get the path to the jsp file? Thanks --Mark - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: javax.naming.NameNotFoundException
On Wed, 23 Oct 2024 19:13:44 Mark Thomas wrote: > > On 23/10/2024 18:57, Mark Foley wrote: > > I'm running Tomcat 8.5.11. I have a hopefully small problem. > > Tomcat 8.5.x is EOL and no longer supported. > > 8.5.11 is also rather old with quite a long list of know security issues. Yeah, I know. Updating it is on my todo list. I'm running 10.1.13 elsewhere, but I have a lot of changes to make getting to 10.x.x so I've been kicking that can down the road. I was hoping this particular issue wasn't dependent on version. > > I have a webapp directory: $CATALINA_HOME/webapps/myapp/. In that directory > > I have WEB-INF/web.xml with: > > > > > >connURL > >jdbc:mysql://localhost/members? > >java.lang.String > > > > > > In this example, the env-entry is just part of an SQL connection string I > > want to snag. > > > > In a browser, going to: /myapp/index.jsp works fine with WEB-INF as > > shown above. > > > > What I want to do is put all of this in a sub-directory: > > $CATALINA_HOME/webapps/myapp/subapp/ and access it on my browser as > > /myapp/subapp/index.jsp. When I do that -- no changes to anything -- > > I get the error: > > That won't work. What will work is renaming: > > $CATALINA_HOME/webapps/myapp > > to > > $CATALINA_HOME/webapps/myapp#subapp/ > > Mark Hmmm ... what I was attempting was splitting many webapps into multiple directories. I have a top-level organization which would be like: $CATALINA_HOME/webapps/GrandWaterBuffalo/ Then subordinate to that would be sub-orgs like: $CATALINA_HOME/webapps/GrandWaterBuffalo/districtA $CATALINA_HOME/webapps/GrandWaterBuffalo/districtB $CATALINA_HOME/webapps/GrandWaterBuffalo/districtC etc. Perhaps 30+ at this level. Then sub-orgs for each of these like: $CATALINA_HOME/webapps/GrandWaterBuffalo/districtA/Chapter1 $CATALINA_HOME/webapps/GrandWaterBuffalo/districtA/Chapter2 $CATALINA_HOME/webapps/GrandWaterBuffalo/districtA/Chapter3 etc. Probably around 10-ish "Chapters" per District. As you can see, this could result in many webapps. I was trying not to put them all under one $CATALINA_HOME/webapps/ directory level, but your example effectively does that. So, no way around this? What do hosting sites do that may have several hundred webapps for different customers? Just put everything under $CATALINA_HOME/webapps? Thanks --Mark - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
FileUpload class not working with Tomcat 10.1
I recently upgraded from Tomcat 10.0.17 to 10.1.13. When I previously upgraded from 9.0.41 to 10.0.17 (back in 2/22) the FileUpload class broke. I fixed that thanks to postings on stackoverflow, but now that I've upgraded to 10.1.13 it is broken again! Here's the error I get: An error occurred at line: [40] in the jsp file: [/schDistImportResults.jsp] The method isMultipartContent(ServletRequestContext) is undefined for the type FileUpload 39: 40: boolean isMultipart = FileUpload.isMultipartContent(new ServletRequestContext(request)); 41: > An error occurred at line: [133] in the jsp file: [/schDistImportResults.jsp] ServletFileUpload cannot be resolved to a type 131: 132: DiskFileItemFactory factory = new DiskFileItemFactory(); // Create a factory for disk-based file items 133: ServletFileUpload upload = new ServletFileUpload(factory); // Create a new file upload handler 134: List items = upload.parseRequest(new ServletRequestContext(request)); // Parse the request 135: Iterator iter = items.iterator(); // Process the uploaded items 136: FileItem item = null; I've checked the RELEASE-NOTES, FAQ and searched the web. I've checked the UploadFile class (no clue) and looked for examples, but none resembled my app. I tried reverting back to the program version I had with 9.0.41, but that didn't work. Here is all I changed in the program between Tomcat versions 9.0.41 and 10.0.17 (which worked): Code: 26,28c26,28 < <%@ page import="org.apache.commons.fileupload.*, < org.apache.commons.fileupload.disk.*, < org.apache.commons.fileupload.servlet.*, --- > <%@ page import="org.apache.tomcat.util.http.fileupload.*, > org.apache.tomcat.util.http.fileupload.disk.*, > org.apache.tomcat.util.http.fileupload.servlet.*, 40c40 < boolean isMultipart = FileUpload.isMultipartContent(request); --- > boolean isMultipart = FileUpload.isMultipartContent(new > ServletRequestContext(request)); 134c134 < List items = upload.parseRequest(request); // Parse the request --- > List items = upload.parseRequest(new ServletRequestContext(request)); > // Parse the request I have quite a few programs that use the FileUpload methods. Does anyone know how to fix this latest breakage? Thanks --Mark - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: FileUpload class not working with Tomcat 10.1
On Fri, 10 Nov 2023 17:11:59 Mark Thomas > On 10/11/2023 16:49, Mark Foley wrote: > > I recently upgraded from Tomcat 10.0.17 to 10.1.13. When I previously > > upgraded > > from 9.0.41 to 10.0.17 (back in 2/22) the FileUpload class broke. I fixed > > that > > thanks to postings on stackoverflow, but now that I've > > upgraded to 10.1.13 it is broken again! Here's the error I get: > > > > An error occurred at line: [40] in the jsp file: [/schDistImportResults.jsp] > > The method isMultipartContent(ServletRequestContext) is undefined for the > > type FileUpload > > Tomcat's internal fork of Commons FileUpload isn't intended for > applications to use. It is not a full fork - just a limited subset of > the functionality Tomcat needs to implement the Servley upload API. > > If you want to use Commons File Upload, add the JAR to your web > application and use it. > > Alternatively, if you want to use the Servlet upload API then use that. > > If the javax.sevlet -> jakarta.servlet transition means you can't use > your preferred version of Commons File Upload in Tomcat 10.1.x (very > likely) then run your preferred version of Commons File Upload through > Tomcat's migration tool for Jakarta EE and use the converted version of > Commons File Upload in your web application. > > Depending on Tomcat internals is very likely to lead to breakage. > > Mark Thanks for your quick reply. Whatever I've been using keeps breaking. I had it working in 9.0.14 and earlier, then it broke with 10.0.17 and I fixed that, now it's broken again with 10.1.13. So, my "prefered" solution is whatever is recommended and is likely to continue to be supported without breaking in future Tomcats. What do you recommend? And do you have a quickie template somewhere which shows the basic include(s) and method I need? I really don't do anything very fancy. My current "basic" implementation is: <%@ page import="org.apache.tomcat.util.http.fileupload.*, org.apache.tomcat.util.http.fileupload.disk.*, org.apache.tomcat.util.http.fileupload.servlet.*, org.apache.commons.io.*" %> DiskFileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); List items = upload.parseRequest(new ServletRequestContext(request)); Iterator iter = items.iterator(); FileItem item = null; while (iter.hasNext()) { item = (FileItem) iter.next(); resultsFile = new File(getServletContext().getRealPath("") + "/tmp/schTaxResults.txt"); try { item.write(resultsFile); } catch ( Exception e) { out.println("Exception: " + e); } } If you could tell me what the officially prefered Apache Tomcat FileUpload mechanism is, and what the correct jar and functions are to accomplish the above, I'd be very grateful! Thanks --Mark > > [deleted] > > I've checked the RELEASE-NOTES, FAQ and searched the web. I've checked the > > UploadFile class (no clue) and looked for examples, but none resembled my > > app. > > I tried reverting back to the program version I had with 9.0.41, but that > > didn't > > work. > > > > Here is all I changed in the program between Tomcat versions 9.0.41 and > > 10.0.17 (which worked): > > Code: > > [deleted] > > > > I have quite a few programs that use the FileUpload methods. Does anyone > > know how to fix this latest breakage? > > > > Thanks --Mark > > - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: FileUpload class not working with Tomcat 10.1
On Fri Nov 10 15:57:50 2023 Christopher Schultz wrote: > > Mark, > > On 11/10/23 12:53, Mark Foley wrote: > > On Fri, 10 Nov 2023 17:11:59 Mark Thomas >> > >> On 10/11/2023 16:49, Mark Foley wrote: > >>> I recently upgraded from Tomcat 10.0.17 to 10.1.13. ... > >>> > >>> [deleted] > >>> > >>> upgraded to 10.1.13 it is broken again! Here's the error I get: > >>> > >>> An error occurred at line: [40] in the jsp file: > >>> [/schDistImportResults.jsp] > >>> The method isMultipartContent(ServletRequestContext) is undefined for the > >>> type FileUpload > >> > >> Tomcat's internal fork of Commons FileUpload isn't intended for > >> applications to use. It is not a full fork - just a limited subset of > >> the functionality Tomcat needs to implement the Servley upload API. > >> > >> [deleted] > > > > My current "basic" implementation is: > > > > <%@ page import="org.apache.tomcat.util.http.fileupload.*, > > org.apache.tomcat.util.http.fileupload.disk.*, > > org.apache.tomcat.util.http.fileupload.servlet.*, > > org.apache.commons.io.*" %> > > > > DiskFileItemFactory factory = new DiskFileItemFactory(); > > ServletFileUpload upload = new ServletFileUpload(factory); > > List items = upload.parseRequest(new ServletRequestContext(request)); > > Iterator iter = items.iterator(); > > FileItem item = null; > > > > while (iter.hasNext()) > > { > > item = (FileItem) iter.next(); > > > > resultsFile = new File(getServletContext().getRealPath("") + > > "/tmp/schTaxResults.txt"); > > > > try { item.write(resultsFile); } > > catch ( Exception e) { out.println("Exception: " + e); } > > } > > > > If you could tell me what the officially prefered Apache Tomcat FileUpload > > mechanism is, and what the correct jar and functions are to accomplish the > > above, I'd be > > very grateful! > > > No offense, but the above is horrifying. All that Java code in a JSP > makes me cringe. You can do this however you want, but I'd recommend > putting Java code into a proper servlet and letting the JSP handle > display only. > > Anyway, I'll get off my soapbox. > > The easiest thing IMO for you to do is stop trying to parse the upload > yourself and use the container. You must have migrated this application > forward for like 10 years or something if you are still using a separate > library to handle multipart-form-uploads. This has been a part of the > code servlet API for some time, now, and you should use it: This program was originally written 9 years ago and I just monkey-typed the original solution from advice and help I found on the web. Likewise, when things broke on my upgrade to Tomcat 10.0.17 I got the "how to fix" from StackOverflow. In short, I've always depended on the kindness of strangers to get this Upload mechaism working! > import jakarta.servlet.http.Part; > > ... > > String contentType = request.getContentType(); > if(null == contentType || !contentType.startsWith("multipart/form-data;")) { > logger.warn("Received non-multipart request"); > > throw new IllegalStateException("Expected multi-part"); > } > > java.io.File tmpDir = > (java.io.File)request.getServletContext().getAttribute("javax.servlet.context.tempdir"); > > java.io.File targetFile = new java.io.File(tmpDir, "schTaxResults.txt"); > > Part fileUpload = request.getPart("param-name"); > > if(null != fileUpload) { > fileUpload.write(targetFile.getAbsolutePath()); > } I've removed my "horrifying" code and put your suggested code in place. I replaced your: throw new IllegalStateException("Expected multi-part"); with: out.println("Expected multi-part"); Just to get things compiling OK. I'll deal with errors later. With that change, it compiled w/o problem. I then attempted an upload. The line: if(null == contentType || !contentType.startsWith("multipart/form-data;")) { returned TRUE so it did detect a multipart upload. Yay! That was a relief However Part fileUpload = request.getPart("param-name"); Gave me the error: java.lang.IllegalStateException: Unable to process parts as no multi-part configuration has been provided So, what does it mean that "no multi-part configuration has been provided"? Is "param-name" something I'm supposed to f
Re: AW: FileUpload class not working with Tomcat 10.1
On Mon Nov 13 02:18:49 2023 "Thomas Hoffmann (Speed4Trade GmbH)" wrote: > Hello, > > > -Ursprüngliche Nachricht----- > > Von: Mark Foley > > Gesendet: Sonntag, 12. November 2023 19:04 > > An: users@tomcat.apache.org > > Betreff: Re: FileUpload class not working with Tomcat 10.1 > > > > On Fri Nov 10 15:57:50 2023 Christopher Schultz > > wrote: > > > > > > Mark, > > > > > > On 11/10/23 12:53, Mark Foley wrote: > > > > On Fri, 10 Nov 2023 17:11:59 Mark Thomas > > >> > > > >> On 10/11/2023 16:49, Mark Foley wrote: > > > >>> I recently upgraded from Tomcat 10.0.17 to 10.1.13. ... > > > >>> > > > >>> [deleted] > > > > > I've put your suggested code in place. > > > > <%@ page import="jakarta.servlet.http.Part" %> > > > > I replaced your: > > > > throw new IllegalStateException("Expected multi-part"); > > > > with: > > > > out.println("Expected multi-part"); > > > > Just to get things compiling OK. I'll deal with errors later. With that > > change, it > > compiled w/o problem. I then attempted an upload. The line: > > > >if(null == contentType || > > !contentType.startsWith("multipart/form-data;")) > > { > > > > returned TRUE so it did detect a multipart upload. Yay! That was a relief > > However > > > >Part fileUpload = request.getPart("param-name"); > > > > Gave me the error: > > > > java.lang.IllegalStateException: Unable to process parts as no multi-part > > configuration has been provided > > > > So, what does it mean that "no multi-part configuration has been provided"? > > Is "param-name" something I'm supposed to fill in? I tried substituting the > > field name, "taxResults", but that gave the same error. > > The form element must have the attribute enctype="multipart/form-data". > Furthermore, the servlet must be annotated by "@MultipartConfig" > > I think for jsp files, there is a similar setting in the web.xml. > This link might help out: > https://stackoverflow.com/questions/37965890/add-annotation-to-jsp Thanks for your reply Thomas. I've checked your suggested link and I have no idea where to put all that stuff. Furthermore, the poster of that issue didn't say he got it working. A respnder to the post said, "Actually every jsp file will be converted to servlet because tomcat can only address servlet and so every jsp file is indirectly a servlet and has all the features of it". I think he is suggesting that the code is superfluous, but not exlpicitly stated as such. I am getting a TRUE return for if(null == contentType || !contentType.startsWith("multipart/form-data;")) so I think it is recognizing it as "multipart/form-data;". Does anyone have an example of a JSP program with jakarta.servlet.http.Part class? I'll search for examples as well, but I really have no idea how to proceed. --Mark F. > > > > > > -chris - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: AW: FileUpload class not working with Tomcat 10.1
On Tue Nov 14 01:46:09 2023 "Thomas Hoffmann (Speed4Trade GmbH)" wrote: > > Hello Mark, > > > -Ursprüngliche Nachricht- > > Von: Mark Foley > > Gesendet: Montag, 13. November 2023 23:12 > > An: users@tomcat.apache.org > > Betreff: Re: AW: FileUpload class not working with Tomcat 10.1 > > > > On Mon Nov 13 02:18:49 2023 "Thomas Hoffmann (Speed4Trade GmbH)" > > wrote: > > > Hello, > > > > > > > -Ursprüngliche Nachricht- > > > > Von: Mark Foley > > > > Gesendet: Sonntag, 12. November 2023 19:04 > > > > An: users@tomcat.apache.org > > > > Betreff: Re: FileUpload class not working with Tomcat 10.1 > > > > > > > > On Fri Nov 10 15:57:50 2023 Christopher Schultz > > > > wrote: > > > > > > > > > > Mark, > > > > > > > > > > On 11/10/23 12:53, Mark Foley wrote: > > > > > > On Fri, 10 Nov 2023 17:11:59 Mark Thomas > wrote: > > > > > >> > > > > > >> On 10/11/2023 16:49, Mark Foley wrote: > > > > > >>> I recently upgraded from Tomcat 10.0.17 to 10.1.13. ... > > > > > >>> > > > > > >>> [deleted] > > > > > > > > > I've put your suggested code in place. > > > > > > > > <%@ page import="jakarta.servlet.http.Part" %> > > > > > > > > I replaced your: > > > > > > > > throw new IllegalStateException("Expected multi-part"); > > > > > > > > with: > > > > > > > > out.println("Expected multi-part"); > > > > > > > > Just to get things compiling OK. I'll deal with errors later. With > > > > that change, it compiled w/o problem. I then attempted an upload. The > > line: > > > > > > > >if(null == contentType || > > > > !contentType.startsWith("multipart/form-data;")) > > > > { > > > > > > > > returned TRUE so it did detect a multipart upload. Yay! That was a > > > > relief However > > > > > > > >Part fileUpload = request.getPart("param-name"); > > > > > > > > Gave me the error: > > > > > > > > java.lang.IllegalStateException: Unable to process parts as no > > > > multi-part configuration has been provided > > > > > > > > So, what does it mean that "no multi-part configuration has been > > provided"? > > > > Is "param-name" something I'm supposed to fill in? I tried > > > > substituting the field name, "taxResults", but that > > gave the same error. > > > > > > The form element must have the attribute enctype="multipart/form- > > data". > > > Furthermore, the servlet must be annotated by "@MultipartConfig" > > > > > > I think for jsp files, there is a similar setting in the web.xml. > > > This link might help out: > > > https://stackoverflow.com/questions/37965890/add-annotation-to-jsp > > > > Thanks for your reply Thomas. > > > > I've checked your suggested link and I have no idea where to put all that > > stuff. Furthermore, the poster of that issue didn't say he got it > > working. > > > > A respnder to the post said, "Actually every jsp file will be converted to > > servlet because tomcat can only address servlet and so every jsp file is > > indirectly a servlet and has all the features of it". I think he is > > suggesting that > > the code is superfluous, but not exlpicitly stated as such. > > > > I am getting a TRUE return for > > > > if(null == contentType || !contentType.startsWith("multipart/form-data;")) > > > > so I think it is recognizing it as "multipart/form-data;". > > > > Does anyone have an example of a JSP program with > > jakarta.servlet.http.Part class? > > > > I'll search for examples as well, but I really have no idea how to proceed. > > > > --Mark F. > > > > The servlet specification defines the special folder WEB-INF. > Within this folder, there is the configuration file named web.xml. > Within this xml-File, the application is configured including the servlets. > JSP-Files are compiled to servlets, either on-the-fly or during compilation > time. > > I
Re: AW: AW: FileUpload class not working with Tomcat 10.1
On Tue Nov 14 14:50:10 2023 "Thomas Hoffmann (Speed4Trade GmbH)" thomas.hoffm...@speed4trade.com.INVALID> wrote: > > Hi Mark! > > > -Ursprüngliche Nachricht- > > Von: Mark Foley > > Gesendet: Dienstag, 14. November 2023 18:20 > > An: users@tomcat.apache.org > > Betreff: Re: AW: FileUpload class not working with Tomcat 10.1 > > > > On Tue Nov 14 01:46:09 2023 "Thomas Hoffmann (Speed4Trade GmbH)" > > wrote: > > > > > > Hello Mark, > > > > > > > -Ursprüngliche Nachricht- > > > > Von: Mark Foley > > > > Gesendet: Montag, 13. November 2023 23:12 > > > > An: users@tomcat.apache.org > > > > Betreff: Re: AW: FileUpload class not working with Tomcat 10.1 > > > > > > > > On Mon Nov 13 02:18:49 2023 "Thomas Hoffmann (Speed4Trade GmbH)" > > > > wrote: > > > > > Hello, > > > > > > > > > > > -Ursprüngliche Nachricht- > > > > > > Von: Mark Foley > > > > > > Gesendet: Sonntag, 12. November 2023 19:04 > > > > > > An: users@tomcat.apache.org > > > > > > Betreff: Re: FileUpload class not working with Tomcat 10.1 > > > > > > > > > > > > On Fri Nov 10 15:57:50 2023 Christopher Schultz > > > > > > wrote: > > > > > > > > > > > > > > Mark, > > > > > > > > > > > > > > On 11/10/23 12:53, Mark Foley wrote: > > > > > > > > On Fri, 10 Nov 2023 17:11:59 Mark Thomas > > > wrote: > > > > > > > >> > > > > > > > >> On 10/11/2023 16:49, Mark Foley wrote: > > > > > > > >>> I recently upgraded from Tomcat 10.0.17 to 10.1.13. ... > > > > > > > >>> > > > > > > > >>> [deleted] > > > > > > > > > > > > > I've put your suggested code in place. > > > > > > > > > > > > <%@ page import="jakarta.servlet.http.Part" %> > > > > > > > > > > > > I replaced your: > > > > > > > > > > > > throw new IllegalStateException("Expected multi-part"); > > > > > > > > > > > > with: > > > > > > > > > > > > out.println("Expected multi-part"); > > > > > > > > > > > > Just to get things compiling OK. I'll deal with errors later. > > > > > > With that change, it compiled w/o problem. I then attempted an > > > > > > upload. The > > > > line: > > > > > > > > > > > >if(null == contentType || > > > > > > !contentType.startsWith("multipart/form-data;")) > > > > > > { > > > > > > > > > > > > returned TRUE so it did detect a multipart upload. Yay! That was > > > > > > a relief However > > > > > > > > > > > >Part fileUpload = request.getPart("param-name"); > > > > > > > > > > > > Gave me the error: > > > > > > > > > > > > java.lang.IllegalStateException: Unable to process parts as no > > > > > > multi-part configuration has been provided > > > > > > > > > > > > So, what does it mean that "no multi-part configuration has been > > > > provided"? > > > > > > Is "param-name" something I'm supposed to fill in? I tried > > > > > > substituting the field name, "taxResults", > > > > > > but that > > > > gave the same error. > > > > > > > > > > The form element must have the attribute enctype="multipart/form- > > > > data". > > > > > Furthermore, the servlet must be annotated by "@MultipartConfig" > > > > > > > > > > I think for jsp files, there is a similar setting in the web.xml. > > > > > This link might help out: > > > > > https://stackoverflow.com/questions/37965890/add-annotation-to-jsp > > > > > > > > Thanks for your reply Thomas. > > > > > > > > I've checked your suggested link and I have no idea where to put all > > > > that stuff
Re: AW: FileUpload class not working with Tomcat 10.1
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 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 definition in WEB-INF/web.xml following the original: uploadfile /1099R-Etrans.jsp /tmp 20848820 418018841 1048576 uploadfile /1099R-Etrans.jsp 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 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? Thanks --Mark On Thu Nov 16 14:36:21 2023 Christopher Schultz 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: > > > > > >uploadfile > > /schDistImportResults.jsp > > > >/tmp > >20848820 > >418018841 > >1048576 > > > > > > > >uploadfile > >/schDistImportResults.jsp > > > > > > I've only changed the and 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("" + 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
Re: FileUpload class not working with Tomcat 10.1
On 4/23/24 18:44, Chuck Caldarale wrote: uploadfile uploadfile /schDistImportResults.jsp The first servlet is named “uploadfile”. On Apr 23, 2024, at 12:42, Mark Foley wrote: Now I need to add another program to the system that does file uploads. I created another definition in WEB-INF/web.xml following the original: uploadfile uploadfile /1099R-Etrans.jsp This second servlet is also named “uploadfile”. 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 definition replaces the first. You gave them the same names, so the second one wins... What magic were you expecting to differentiate between the two? - Chuck I can easily change the name of the second servlet, but how would the respective jsp programs (schDistImportResults.jsp, 1099R-Etrans.jsp) specify one or the other? The programs do: String contentType = request.getContentType(); if (contentType.startsWith("multipart/form-data;")) { Part fileUpload = request.getPart("taxResults"); // for schDistImportResults.jsp // or Part fileUpload = request.getPart("vendor1099-MISC"); // for 1099R-Etrans.jsp InputStream inFile = fileUpload.getInputStream(); : } That's it. There is nothing in the program that specifies a servlet name. My initial servlet definition (for schDistImportResults.jsp) was based on the XML suggestion from Christopher Schultz back in November, 2023. Since only the one jsp program was involved, there was no discussion of how to specify more than one program in web.xml. So, I can (and will) give the servlets different names in web.xml, but how does the jsp program select the one for its use? Thanks --Mark
Re: FileUpload class not working with Tomcat 10.1
On 5/7/2024 4:52 PM, Christopher Schultz wrote: Mark, On 5/3/24 12:16, Mark Foley wrote: On 4/23/24 18:44, Chuck Caldarale wrote: uploadfile uploadfile /schDistImportResults.jsp The first servlet is named “uploadfile”. On Apr 23, 2024, at 12:42, Mark Foley wrote: Now I need to add another program to the system that does file uploads. I created another definition in WEB-INF/web.xml following the original: uploadfile uploadfile /1099R-Etrans.jsp This second servlet is also named “uploadfile”. 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 definition replaces the first. You gave them the same names, so the second one wins... What magic were you expecting to differentiate between the two? - Chuck I can easily change the name of the second servlet, but how would the respective jsp programs (schDistImportResults.jsp, 1099R-Etrans.jsp) specify one or the other? The programs do: String contentType = request.getContentType(); if (contentType.startsWith("multipart/form-data;")) { Part fileUpload = request.getPart("taxResults"); // for schDistImportResults.jsp // or Part fileUpload = request.getPart("vendor1099-MISC"); // for 1099R-Etrans.jsp InputStream inFile = fileUpload.getInputStream(); : } That's it. There is nothing in the program that specifies a servlet name. My initial servlet definition (for schDistImportResults.jsp) was based on the XML suggestion from Christopher Schultz back in November, 2023. Since only the one jsp program was involved, there was no discussion of how to specify more than one program in web.xml. So, I can (and will) give the servlets different names in web.xml, but how does the jsp program select the one for its use? Does the JSP need to reference the "program" (servlet?) at all? The program, as shown above didn'twork at all until I put that servlet definition on WEB-INF/web.xml, so I suppose the answer is "yes". As to why, I have not a clue. When you make a request, Tomcat determines which servlet in your application will service the request. If that's a JSP, then the JSP is invoked. A JSP just compiles to a servlet, just as if you had written a .java file with a class that "extends HttpServlet" or similar. It's not clear what "the program" is: JSP or servlet? Or something else? The programs are written in Java/JSP and, yes, Tomcat "compiles" them to .class -- probably servlets. It's also not clear how "the program" would or should reference a servlet name. Maybe you can explain (again)? -chris I think I may have figured this out. Here are my two servlet definitions in WEB-INF/web.xml: uploadfile /schDistImportResults.jsp /tmp 20848820 418018841 1048576 uploadfile /schDistImportResults.jsp *upload1099* /1099R-Etrans.jsp /tmp 20848820 418018841 1048576 *upload1099* /1099R-Etrans.jsp In the 2nd definition, Taking Chuck's hint, I changed the servlet-name to "upload1099". That seemed to work for the 1099R-Etrans.jsp program, but I haven't been able to test the schDistImportResults.jsp program yet to see if I broke that one. Why these definitions are needed in web.xml and how all that works under the hood is, as Chuck said, "magic".