codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Link doesn`t display full file name  sherbir at 06:28 on Saturday, July 17, 2004
 

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("/index.html"); // 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("<font face=verdana size=3>");
out.println("<center>");
out.println("<font color=red><b><u>CONGRATULATIONS !!</u></b></font>");

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("<hr>");
out.println("<br>");
out.println("What would you like to do next ?");
out.println("<br>");
out.println("<br>");
out.println("<font size=1>");
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("</font>");
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.


  Re: Link doesn`t display full file name  glamgirl at 20:28 on Friday, January 07, 2005
 

Encoding a url replaces spaces with +.
The easiest solution might be to just remove the spaces in filenames.








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  How to dynamically create a calendar when I click a button?
•  c++ tutorials
•  Update a second table
•  Trackin Site behaviour
•  variable scope problem
•  dynamic crystal report generation
•  execute an Excel macro when the sheet is changed from ASP.NET
•  Re: form
•  form


Recent Articles
Communicating with the Database (Using ADO)
MagicGrid
Simple Thumbnail Browsing Solution
Type Anywhere
A Better Moustrap: FmtDate to replace FormatDateTime
ASP.NET Forum Source Code
Internal Search Engine
Javascript Growing Window
Simple date validation
Search engine friendly URLs using ASP.NET (C#.NET)


Site Survey
Help us serve you better. Take a five minute survey. Click here!

© Copyright codetoad.com 2001-2005