Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > J2EE
|
J2EE General J2EE (Java 2 Enterprise Edition) discussions. Questions not specific to EE will be redirected elsewhere.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the J2EE section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 17th, 2004, 12:30 AM
Authorized User
 
Join Date: Jul 2004
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to sherbir
Default Link doesn't display full file name

I'm using the com.oreilly.servlet package in my project to upload a file thru servlets.

It's working just fine.

Here's the full code in the doPost method of the servlet :

String fname="";

String server_path=""; // Specifies the server's root folder.
String upload_directory=""; // Specifies the path of the directory on the server where the file will be saved.

String complete_path=""; // specifies the complete path.


String encoded_file_name=""; // to encode the file name in UTF-8 format.


res.setContentType("text/html");
PrintWriter out = res.getWriter();
server_path = getServletContext().getRealPath("/"); // getting the server's root directory.

upload_directory = "\\sherbir\\uploaded_files"; // path of the uploaded files' directory.

complete_path = server_path + upload_directory; // complete server path for uploading the file.

MultipartRequest mpr = new MultipartRequest(req,complete_path); // upload the file.

Enumeration files = mpr.getFileNames(); // obtaining names of all uploaded files.

out.println("<br><br>");
out.println("");
out.println("<center>");
out.println("<b>[u]CONGRATULATIONS !!</u></b>");

String name = (String) files.nextElement();
fname = mpr.getFilesystemName(name); // getting the name of the uploaded file.

out.println("Your file <b><i>" + fname + "</i></b> was successfully uploaded.");

fname=URLEncoder.encode(fname,"UTF-8");
out.println("<br>");
out.println("fname = " + fname);

out.println("<br>");
out.println("");
out.println("<br>");
out.println("What would you like to do next ?");
out.println("<br>");
out.println("<br>");
out.println("");
out.println("<b><a href=http://localhost:8080/examples/sherbir/uploaded_files/" + fname + ">View .RTF file</a></b>");
out.println(" ");
out.println("<b><a href=http://localhost:8080/examples/upload_file_html.html>Upload another file</a></b>");
out.println(" ");
out.println("<b><a href=javascript:window.close()>Close this Window</a></b>");
out.println("");
out.println("</center>");
}
catch (Exception e) {}

I have placed client-side validations to upload only .DOC/.RTF files.
The files are uploading successfully.

The problem is that if I upload a file names "Java Security.doc" and then when I place the cursor on the link (View .RTF File), it shows the file name as "Java+Security" and gives the following error :

message :- /examples/sherbir/uploaded_files/Java+Security.doc

description :- The requested resource (/examples/sherbir/uploaded_files/Java+Security.doc) is not available.

If I specify the file name as a URLEncoded one, then the file name I get on placing the cursor on the link is simply "Java"...the rest of the file name is missing.

How do I get around this problem ? Please advise.

Regards,
Sherbir
__________________
Regards,
Sherbir





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to call file using full path labby C# 2005 4 September 27th, 2006 11:25 PM
How can I display a download link in my (C#) ASP.N MichaelChang C# 1 February 10th, 2005 06:00 AM
Display Problem: Navigating LINK maahee ADO.NET 0 April 24th, 2004 10:44 AM
Retrive full path name from uploaded file itsp PHP How-To 3 June 10th, 2003 07:02 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.