File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Problems creating dynamic clickable document list Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Problems creating dynamic clickable document list" Watch "Problems creating dynamic clickable document list" New topic
Author

Problems creating dynamic clickable document list

Matt Senecal
Ranch Hand

Joined: Dec 01, 2000
Posts: 255
I'm trying to create a JSP that reads the contents of a directory and creates a list of links to the files in that directory. The idea is that the user should be able to click on one of the links, and open the file up.

The code correctly creates a list of hyperlinked files, but when I click on the links, the files do not open. No dialog comes up, or anything.

Can anyone tell me what I'm doing wrong?

My page code is as follows:

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

Two questions:

1) Why do you complicate your JSP pages needlessly by generating HTML in Java code such as:



You're in a JSP page. Use template text for markup.

2) What do you see at the browser via View Source? Is your HTML as you expected?

(Hint: you will discover that your HTML is not well-formed, and it's difficult to see why in the code because of the first issue)
[ October 20, 2004: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Matt Senecal
Ranch Hand

Joined: Dec 01, 2000
Posts: 255

1) Why do you complicate your JSP pages needlessly by generating HTML in Java code


Because you're looking at what is literally my first attempt at a JSP after less than a day of study. It naturally follows that it's going to contain things that look funny/inefficient/complicated to someone who knows more than I do.



2) What do you see at the browser via View Source? Is your HTML as you expected?


Pretty much!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

That's cool. So that's lesson one: the less Java in your JSPs, the better. I prefer none at all, but that's another show as they say.

Why not post the resulting HTML from your View Source? That'll give us a better look at why your links may not be working.
Matt Senecal
Ranch Hand

Joined: Dec 01, 2000
Posts: 255

Why not post the resulting HTML from your View Source? That'll give us a better look at why your links may not be working.


No problem! I appreciate your help.

I altered the source slightly. I guess my brain isn't working today, because I totally forgot that arrays have a length property! That's been fixed. I also added explicit quotes to the links.

The links still don't work. However, if I copy the link shortcuts and paste them into the address bar of my browser, the files open fine. Puzzling.

The resulting HTML is below:

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

Valid file protocol URLs are of the form:

Matt Senecal
Ranch Hand

Joined: Dec 01, 2000
Posts: 255
IE6 correctly interprets the URL's that my code created as files. That is, when you do a copy link, they come out as "file:///BLAHBLAH". I tried doing it explicitly anyway, and the results were the same.

Originally posted by Bear Bibeault:
Valid file protocol URLs are of the form:

Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

Matt ,

did you try creating a new html with your view source code ??
and opening same in browser.

are you still not able to open file ?

in that case there would be nothig releated to your jsp code.


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
Matt Senecal
Ranch Hand

Joined: Dec 01, 2000
Posts: 255
Yes, I just tried it, and it works fine. I'm looking to see if my web server isn't preventing it.

Originally posted by Shailesh Chandra:
Matt ,

did you try creating a new html with your view source code ??
and opening same in browser.

are you still not able to open file ?

in that case there would be nothig releated to your jsp code.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

I copied your output to a plain html file and it operated without problems. One thing you might look into is how the browser is configured to handle various MIME types. It may be having problems dealing with files without file types.

Does the .txt file link work? The browser should know how to handle that file type.

P.S. You do realize that this will only work when the client and the server are the same machine, right?
[ October 20, 2004: Message edited by: Bear Bibeault ]
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

why dont you try relative paths for your files.

put your files in a folder with jsp just for testing purpose and test the same.
rahul V kumar
Ranch Hand

Joined: May 20, 2003
Posts: 82
Where are you running the jsp page? I guess its on your local machine.

If its running on some other machine then its possible that you do not have the files in c:\temp directory of that machine .
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1081

Originally posted by rahul V kumar:

If its running on some other machine then its possible that you do not have the files in c:\temp directory of that machine .



If Html created from view soure code works fine then there MUST be files in c:\temp directory and jsp's are running on local machine.

But for other machine this might be the case.
[ October 20, 2004: Message edited by: Shailesh Chandra ]
 
jQuery in Action, 2nd edition
 
subject: Problems creating dynamic clickable document list