• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to print out contents of a File

 
jonas okwara
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I really need some direction on how to print the contents of a text file
in JSP. I have a getEmployeeList() bean which uses the System.out.println()
method to print out the contents of this file.

Please how can I best Implement this considering JSP does not understand
the System.out.println() command.

thank you
Jonas
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the file is addressable via URL, the JSTL <c:import> tag will read and display the file.
 
Gary Dhaliwal
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think its a best practice to print from within the method. I think the method should return a list or array. And to print it in your JSP:

<% ArrayList<Employee> employees = (ArrayList)request.getAttribute("employees"); %>

Lorem Ipsum ...

<% for(int i=0;i<employees.size();i++){
out.println(employees.get(i).getName());
} %>
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Best practices also dictate that there should be no Java code in a JSP.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!