Listing files
Hi,
I have a simple requirement.I am packaging a war file with a whole bunch of .txt files files.
I need to find a way to display the files with a link so that when the filename is clicked,it displays the contents.
I want this program to list out the files with .txt to be within the war file itself.Then find a way to call this thro some jsp or servlet.
Any ideas please help me.
Thanks
[424 byte] By [
mort2007a] at [2007-11-26 21:39:13]

# 1
Using Java File I/O read the directory contents where your text files are located.
Store the list of text files in a List of JavaBeans , use a Java Servlet to access this JavaBean.
Use the Servlet to forward the List of JavaBeans , to a JSP ,
Inside the JSP access the List of JavaBeans with a jsp:useBean tag, and iterate through the list with JSTL 1.1 , c:forEach tag and print the list of files in the directory.
Then, modify the HTML , and add an HTML anchor tag , around each file name, and specify the URL to each file name, since you already know where those files are located.
Do additional research on the above steps, and try to implement it.
# 2
thanks..I will definitely look into this option.but isnt there a much simpler way:-)..Thanks very much.,.,duke dollars ur way!
# 3
I do agree that it is complex to set-up when you're first building the project.
What you're doing is building the various components, which can later be re-used by other components of your project.
By separating file access (Java File I/O) , view (JSP ) and controller (Servlet, that routes JSPs) - you're essentially building separate components that do best at what they're dedicated to do.
Some people write the entire page or application logic in the JSP alone, without utilizing Servlets, JavaBeans and Java classes. This process appears easy at first but, one soon realizes how messy and unmanageable the code becomes.
That's why it is highly encouraged that one uses JSPs only for displaying data and for rendering the view.
Also JSPs have a feature called JSP Scriptlets and Expressions, the use of scriptlets is highly discouraged because it leads to very messy code - instead you could write much cleaner and easier code with JSTL1.1.
I feel tempted to write this application for you :-), but I don't have the time, plus if I write it out you won't learn much - once you get over the basics things start to become easier.
It sounds like a good exercise, I might write it over the weekend.
# 4
hey thanks very much,,may be u cud review my code..that is wonderful.Cud u give me an email id that i cud email u.Thnaks
# 5
You could post your code right here, that way if I'm busy or unavailable someone else would be able to help you, and there are people on this forum who know better than I do.
Use the code button , to wrap your code so that it highlights the syntax and is easier to read.
I hope you know how to set-up JDK (latest is better) and Tomcat (latest version).
You might need help with JSTL 1.1, but you can cross the bridge when you come to it.