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:
<servlet>
<servlet-name>uploadfile</servlet-name>
<snip/>
</servlet>
<servlet-mapping>
<servlet-name>uploadfile</servlet-name>
<url-pattern>/schDistImportResults.jsp</url-pattern>
</servlet-mapping>
The first servlet is named “uploadfile”.
On Apr 23, 2024, at 12:42, Mark Foley<mfo...@novatec-inc.com> wrote:
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>
<snip/>
</servlet>
<servlet-mapping>
<servlet-name>uploadfile</servlet-name>
<url-pattern>/1099R-Etrans.jsp</url-pattern>
</servlet-mapping>
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 <servlet> 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:
<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>
<servlet>
<servlet-name>*upload1099*</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>*upload1099*</servlet-name>
<url-pattern>/1099R-Etrans.jsp</url-pattern>
</servlet-mapping>
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".