AW: Cannot upload an image file from a deployed JSP page in Tomcat 10
Hallo Lauri, > -Ursprüngliche Nachricht- > Von: Lauri > Gesendet: Montag, 29. Mai 2023 11:36 > An: users@tomcat.apache.org > Betreff: Cannot upload an image file from a deployed JSP page in Tomcat 10 > > 1) Summary of the problem: > > From Tomcat 10 and onwards there has been a move from Java EE to Jakarta > EE as part of the transfer of Java EE to the Eclipse Foundation, the primary > package for all implemented APIs has changed from javax.* to jakarta.*. > > I have a JSP page deployed in Tomcat 10 that is intended to upload a file > from the desktop (Windows 10) to the server where Tomcat 10 is running > (OEL 8). > I am unable to upload an image, and I get this error: > - > org.apache.jasper.JasperException: Unable to compile class for JSP: > An error occurred at line: [24] in the jsp file: [/index.jsp] The type > javax.servlet.http.HttpServletRequest cannot be resolved. It is indirectly > referenced from required type > org.apache.commons.fileupload.servlet.ServletFileUpload > 21: ServletFileUpload upload = new ServletFileUpload(factory); > 22: > 23: // Parse the request > 24: List items = upload.parseRequest(request); > 25: > 26: // Process the uploaded items > 27: Iterator iter = items.iterator(); > - > > My application name: TESTS > I have these libraries for the TESTS application: > /u01/tomcat/base/middleware/tomcat10/webapps/TESTS/WEB-INF/lib: > commons-fileupload-1.5-test-sources.jar > commons-fileupload-1.5-tests.jar > commons-fileupload-1.5-sources.jar > commons-fileupload-1.5-javadoc.jar > commons-fileupload-1.5.jar > > I have in my Tomcat 10 this library: > /u01/tomcat/base/middleware/tomcat10/lib: > -rw-r--r--. 1 tomcat tomcat 365905 Apr 25 12:16 servlet-api.jar > > 2) The deployed JSP page: > > - > <%@ page import="org.apache.commons.fileupload.*" %> <%@ page > import="org.apache.commons.fileupload.disk.*" %> <%@ page > import="org.apache.commons.fileupload.servlet.*" %> <%@ page > import="java.io.*" %> <%@ page import="java.util.*" %> <%@ page > import="jakarta.servlet.*" %> <%@ page import="jakarta.servlet.http.*" %> > <%@ page import="jakarta.sql.*" %> <%@ page import="java.sql.*" %> > <%@ page > import="org.apache.commons.fileupload.disk.DiskFileItemFactory" %> <%@ > page import="org.apache.commons.fileupload.FileItemFactory" %> > > <% > // Set the upload directory > String uploadDir = "/tmp/"; > > // Create a factory for disk-based file items FileItemFactory factory = new > DiskFileItemFactory(); > > // Create a new file upload handler > ServletFileUpload upload = new ServletFileUpload(factory); > > // Parse the request > List items = upload.parseRequest(request); > > // Process the uploaded items > Iterator iter = items.iterator(); while (iter.hasNext()) { > FileItem item = iter.next(); > > // If the item is a file, save it to the upload directory > if (!item.isFormField()) { > String fileName = new File(item.getName()).getName(); > String filePath = uploadDir + fileName; > File uploadedFile = new File(filePath); > item.write(uploadedFile); > } > } > %> > > > File Upload Example > > > File Upload Example > > > > > > > > - > > I have found that it looks like: > https://www.linuxquestions.org/questions/linux-server-73/fileupload-class- > not-working-with-tomcat-10-a-4175710078/ > But in my situation, it seems to be a different problem. > > Does someone know if this is related to a bug ? > Do I use the correct servlet-api jar package ? > Do Tomcat 10 need to be specifically configured for using servlet-api and > jakarta EE packages ? > Does someone know what can be the problem ? > > Thanks by advance for any tip(s) and/or suggestion(s). I had the same issue because I used internal Tomcat classes. In the past the servlet specification didn't have methods to deal with multipart uploads. Since Servlet 3.0 there are methods for retrieving the uploads: https://docs.oracle.com/javaee/6/tutorial/doc/gmhba.html I replace the ServletFileUpload and used standard methods like getParts(). This worked for me. Greetings, Thomas - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: [ANN] Apache Tomcat 9.0.75 available
On 29/05/2023 08:56, Greg Huber wrote: Hello, Looking through my logs I am seeing a few: org.apache.catalina.connector.ClientAbortException: java.io.IOException: Broken pipe Checking previous logs for 9.0.74, there were none, and I have not made any changes to my app. Were there any changes that would cause these? Nothing obvious. It is AJP so that suggests the proxy is closing the connection before Tomcat expects it to. That might happen for a 400 response but to be honest, I'd expect the proxy to read the full response before closing the connection. There was some tightening up of HTTP request header validation that might cause a few more 400 responses but I'd be surprised since the proxy should have rejected those requests before forwarding them anyway. The extra checks are for HTTP headers without names. i.e.: : ValueButNoName Maybe check if the client is sending such a header? Mark - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: Cannot upload an image file from a deployed JSP page in Tomcat 10
On 29/05/2023 10:36, Lauri wrote: From Tomcat 10 and onwards there has been a move from Java EE to Jakarta EE as part of the transfer of Java EE to the Eclipse Foundation, the primary package for all implemented APIs has changed from javax.* to jakarta.*. Note the above. I have these libraries for the TESTS application: /u01/tomcat/base/middleware/tomcat10/webapps/TESTS/WEB-INF/lib: commons-fileupload-1.5-test-sources.jar commons-fileupload-1.5-tests.jar commons-fileupload-1.5-sources.jar commons-fileupload-1.5-javadoc.jar You should not have any of the above in your web application. commons-fileupload-1.5.jar That library uses the Java EE APIs so it won't work with Tomcat 10 as you have discovered. Does someone know if this is related to a bug ? No. There is no bug. Do I use the correct servlet-api jar package ? If you are using Tomcat 10, you need to use the Jakarta EE package names. You can't use the Java EE package names. You can't use any library that uses the Java EE package names. Do Tomcat 10 need to be specifically configured for using servlet-api and jakarta EE packages ? No. Does someone know what can be the problem ? See above. You are trying to use a Java EE library with Jakarta EE. Thanks by advance for any tip(s) and/or suggestion(s). Option 1. Write your web application using the Jakarta EE APIs. Use the Tomcat migration tool for Jakarta EE to convert commons-fileupload-1.5.jar from from Java EE to Jakarta EE (and any other libraries using the Java EE APIs). Deploy your web application with the converted JARs. Option 2. Write your web application using the Java EE APIs and then deploy it to webapps-javaee rather than webapps and Tomcat will use the migration tool to convert your web application for you. Option 3. Write your web application using the Java EE APIs and convert it to Jkarata EE using the migration tool. Once converted, deploy it to the webapps directory. Note: If you use any deprecated Java EE APIs you may still see failures after conversion as Jakarta EE 10 most of the deprecated APIs. Mark - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Cannot upload an image file from a deployed JSP page in Tomcat 10
1) Summary of the problem: >From Tomcat 10 and onwards there has been a move from Java EE to Jakarta EE as >part of the transfer of Java EE to the Eclipse Foundation, the primary package >for all implemented APIs has changed from javax.* to jakarta.*. I have a JSP page deployed in Tomcat 10 that is intended to upload a file from the desktop (Windows 10) to the server where Tomcat 10 is running (OEL 8). I am unable to upload an image, and I get this error: - org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: [24] in the jsp file: [/index.jsp] The type javax.servlet.http.HttpServletRequest cannot be resolved. It is indirectly referenced from required type org.apache.commons.fileupload.servlet.ServletFileUpload 21: ServletFileUpload upload = new ServletFileUpload(factory); 22: 23: // Parse the request 24: List items = upload.parseRequest(request); 25: 26: // Process the uploaded items 27: Iterator iter = items.iterator(); - My application name: TESTS I have these libraries for the TESTS application: /u01/tomcat/base/middleware/tomcat10/webapps/TESTS/WEB-INF/lib: commons-fileupload-1.5-test-sources.jar commons-fileupload-1.5-tests.jar commons-fileupload-1.5-sources.jar commons-fileupload-1.5-javadoc.jar commons-fileupload-1.5.jar I have in my Tomcat 10 this library: /u01/tomcat/base/middleware/tomcat10/lib: -rw-r--r--. 1 tomcat tomcat 365905 Apr 25 12:16 servlet-api.jar 2) The deployed JSP page: - <%@ page import="org.apache.commons.fileupload.*" %> <%@ page import="org.apache.commons.fileupload.disk.*" %> <%@ page import="org.apache.commons.fileupload.servlet.*" %> <%@ page import="java.io.*" %> <%@ page import="java.util.*" %> <%@ page import="jakarta.servlet.*" %> <%@ page import="jakarta.servlet.http.*" %> <%@ page import="jakarta.sql.*" %> <%@ page import="java.sql.*" %> <%@ page import="org.apache.commons.fileupload.disk.DiskFileItemFactory" %> <%@ page import="org.apache.commons.fileupload.FileItemFactory" %> <% // Set the upload directory String uploadDir = "/tmp/"; // Create a factory for disk-based file items FileItemFactory factory = new DiskFileItemFactory(); // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); // Parse the request List items = upload.parseRequest(request); // Process the uploaded items Iterator iter = items.iterator(); while (iter.hasNext()) { FileItem item = iter.next(); // If the item is a file, save it to the upload directory if (!item.isFormField()) { String fileName = new File(item.getName()).getName(); String filePath = uploadDir + fileName; File uploadedFile = new File(filePath); item.write(uploadedFile); } } %> File Upload Example File Upload Example - I have found that it looks like: https://www.linuxquestions.org/questions/linux-server-73/fileupload-class-not-working-with-tomcat-10-a-4175710078/ But in my situation, it seems to be a different problem. Does someone know if this is related to a bug ? Do I use the correct servlet-api jar package ? Do Tomcat 10 need to be specifically configured for using servlet-api and jakarta EE packages ? Does someone know what can be the problem ? Thanks by advance for any tip(s) and/or suggestion(s).
Re: [ANN] Apache Tomcat 9.0.75 available
Hello, Looking through my logs I am seeing a few: org.apache.catalina.connector.ClientAbortException: java.io.IOException: Broken pipe at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:351) ~[catalina.jar:9.0.75] at org.apache.catalina.connector.OutputBuffer.flushByteBuffer(OutputBuffer.java:784) ~[catalina.jar:9.0.75] at org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:298) ~[catalina.jar:9.0.75] at org.apache.catalina.connector.OutputBuffer.close(OutputBuffer.java:250) ~[catalina.jar:9.0.75] at org.apache.catalina.connector.CoyoteOutputStream.close(CoyoteOutputStream.java:153) ~[catalina.jar:9.0.75] . at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:178) [catalina.jar:9.0.75] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:153) [catalina.jar:9.0.75] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:167) [catalina.jar:9.0.75] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:90) [catalina.jar:9.0.75] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:481) [catalina.jar:9.0.75] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:130) [catalina.jar:9.0.75] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93) [catalina.jar:9.0.75] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) [catalina.jar:9.0.75] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) [catalina.jar:9.0.75] at org.apache.coyote.ajp.AjpProcessor.service(AjpProcessor.java:422) [tomcat-coyote.jar:9.0.75] at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63) [tomcat-coyote.jar:9.0.75] at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:926) [tomcat-coyote.jar:9.0.75] at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1791) [tomcat-coyote.jar:9.0.75] at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52) [tomcat-coyote.jar:9.0.75] at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) [tomcat-util.jar:9.0.75] at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) [tomcat-util.jar:9.0.75] at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-util.jar:9.0.75] at java.lang.Thread.run(Thread.java:829) [?:?] Caused by: java.io.IOException: Broken pipe at sun.nio.ch.FileDispatcherImpl.write0(Native Method) ~[?:?] at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:47) ~[?:?] at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:113) ~[?:?] at sun.nio.ch.IOUtil.write(IOUtil.java:79) ~[?:?] at sun.nio.ch.IOUtil.write(IOUtil.java:50) ~[?:?] at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:462) ~[?:?] at org.apache.tomcat.util.net.NioChannel.write(NioChannel.java:136) ~[tomcat-coyote.jar:9.0.75] at org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.doWrite(NioEndpoint.java:1431) ~[tomcat-coyote.jar:9.0.75] at org.apache.tomcat.util.net.SocketWrapperBase.doWrite(SocketWrapperBase.java:775) ~[tomcat-coyote.jar:9.0.75] at org.apache.tomcat.util.net.SocketWrapperBase.writeBlocking(SocketWrapperBase.java:573) ~[tomcat-coyote.jar:9.0.75] at org.apache.tomcat.util.net.SocketWrapperBase.write(SocketWrapperBase.java:497) ~[tomcat-coyote.jar:9.0.75] at org.apache.coyote.ajp.AjpProcessor.writeData(AjpProcessor.java:1235) ~[tomcat-coyote.jar:9.0.75] at org.apache.coyote.ajp.AjpProcessor.access$600(AjpProcessor.java:59) ~[tomcat-coyote.jar:9.0.75] at org.apache.coyote.ajp.AjpProcessor$SocketOutputBuffer.doWrite(AjpProcessor.java:1315) ~[tomcat-coyote.jar:9.0.75] at org.apache.coyote.Response.doWrite(Response.java:603) ~[tomcat-coyote.jar:9.0.75] at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:338) ~[catalina.jar:9.0.75] ... 151 more . java.lang.IllegalStateException: Cannot call sendError() after the response has been committed at org.apache.catalina.connector.ResponseFacade.checkCommitted(ResponseFacade.java:530) ~[catalina.jar:9.0.75] at org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:355) ~[catalina.jar:9.0.75] at javax.servlet.http.HttpServletResponseWrapper.sendError(HttpServletResponseWrapper.java:111) ~[servlet-api.jar:4.0.FR] at javax.servlet.http.HttpServletResponseWrapper.sendError(HttpServletResponseWrapper.java:111) ~[servlet-api.jar:4.0.FR] Checking previous logs for 9.0.74, there were none, and I have not made any changes to my app.