Jakarta Commons FileUpload, error in file name extraction.

I

i730lover

Scenario :
I am using Jakarta Commons FileUpload 1.0 package, to upload files.
I use multipart/form-data as uploading form.
Jsp file will show info regarding uploaded files.

Problem :
In production server, uploaded files names are shown, with thier full
paths,
when internet explorer is used. I just want to extract file names only.
To do it, I am making a new file and extracting the name.
This works fine on windows environment, but not on linux.
Any suggestions ?

Testing :
Tomcat version is 5.5.9
JDK 1.5.0_05
Testing on Windows XP.
Works fine with any browser.

Production :
Tomcat version is 5
JDK 1.5.0_05
Linux OS
Dosent work with IE


<html>
<head>
<title>File Upload2</title>
</head>

<body>
<h1>Welcome to upload2.</h1>

<form action="upload2.jsp" method="post"
enctype="multipart/form-data">
<p><br/>
Choose a photo to be uploaded to the server:
<input name="myFileUpload2" type="file"/><br/>
</p>

<hr/>

<p>
<input type="submit"/>
<input type="reset"/>
</p>
</form>
</body>
</html>











<%@page import="org.apache.commons.fileupload.*, java.util.*,
java.io.File, java.lang.Exception" %>

<html>
<head>
<title>File Upload</title>
</head>

<body>
<h1>Data Received at the Server</h1>
<hr/>
<p>

<%
if (FileUpload.isMultipartContent(request)){

DiskFileUpload diskFileUpload = new DiskFileUpload();
List fileItemsList = diskFileUpload.parseRequest(request);

Iterator it = fileItemsList.iterator();
FileItem fileItem = (FileItem)it.next();


if (fileItem!=null){

String fileName = fileItem.getName();
File renamedFile = new File(
getServletContext().getRealPath("/styles/TB/"), fileItem.getName());

%>
<b>Uploaded File Info:</b><br/>
Content type: <%= fileItem.getContentType() %><br/>
Field name: <%= fileItem.getFieldName() %><br/>
File name: <%= fileName %><br/>
New File name: <%= renamedFile.getName() %><br/>
File size: <%= fileItem.getSize() %><br/><br/>
<%
}
}
%>

</p>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top