Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problems creating dynamic clickable document list

 
Matt Senecal
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64692
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Matt Senecal
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Pie
Posts: 64692
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Pie
Posts: 64692
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Valid file protocol URLs are of the form:

 
Matt Senecal
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Matt Senecal
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64692
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1082
Java Oracle Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic