I've recently just got my web application on a linux server running tomcat. Running the application locally on my Windows computer allows me to upload an XML file with no problem, but now that it's on the tomcat server, I keep getting NullPointerExceptions.
Here is the part of the servlet that receives the file:
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException, ParserConfigurationException, SAXException, ResponseException {
response.setContentType("text/html;charset=UTF-8");
//Create path components to save the file
final Part filePart = request.getPart("XMLFile"); // Retrieves <input type="file" name="XMLFile">
final String path = "/opt/tomcat/bin";
final String fileName = getFileName(filePart);
OutputStream outStream = null;
InputStream fileContent = null;
final PrintWriter out = response.getWriter();
try {
//File xmlFile = new File(path + File.separator + fileName);
File xmlFile = new File(fileName);
outStream = new FileOutputStream(xmlFile);
fileContent = filePart.getInputStream();
...
The line "File xmlFile = new File(fileName)" throws a FileNotFoundException in a later catch statement. I've tried a bunch of different possibilities, but I can't find the error.
With some lines of code I end up with the file path being "opt/tomcat/bin/(name of my xml file)" and other times it will be "opt/tomcat/bin/opt/tomcat/bin/(name of my xml file)" but none of them work.
Any ideas what the error could be?
Here's the form on my JSP page that handles the file upload:
<form style="text-align: center" style="position: relative" style="right: auto" style="left: auto" action="upload" method="post" enctype="multipart/form-data">
<h3>Upload your iTunes library</h3>
<input style="margin: 0 auto" name="XMLFile" id="file" type="file"/>
<br>
<input type="submit" value="Submit" formmethod="post" formaction="GetItunesLibrary"/>
</form>