Win a copy of Learn Java with Math: Using Fun Projects and Games this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Junilu Lacar
  • Martin Vashko
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Scott Selikoff
  • salvin francis
  • Piet Souris

Read and Display server.log? Pls HELP

 
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi :
I need to read a c://jboss/server.log
The content of this file is ascii and it look like below
12:17:0.0 ERROR Something a
12:18:0.0 ERROR Something b
12:19:0.0 INFO Something b
12:20:0.0 DEBUG Something d

1. How to I read this file?
2. HOw do I display this file back to the JSP? I am using Spring Framework and HttpServletRequest, HttpServletResponse

3. How do I "filter" out only display information for "ERROR" or "INFO" on this log file

Many thanks in advance for your help
Regards.
 
Rancher
Posts: 43011
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

1. How to I read this file?


Are you familiar with the java.io.package? This code snippet shows how to read a file line by line.

You should read the file in a servlet or Java class, not in a JSP.

2. How do I display this file back to the JSP? I am using Spring Framework and HttpServletRequest, HttpServletResponse


During reading the file, store each line as an item in a collection, which you then add as a request attribute. In the JSP you can then iterate over the collection and output each line as needed.

3. How do I "filter" out only display information for "ERROR" or "INFO" on this log file


Only add lines that contain "ERROR" of "INFO" (the String.indexOf method can test this). If you want to display all messages having a level equal to or higher than INFO, it gets a bit more complicated, but not much.
 
jay lai
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Ulf Dittmer :
Thanks so much for your hints, I am trying the new java.util.Scanner in 1.5 JDK.

I have the following method to read the file, how do I read the line and put into collection , can you give me one more hint. Greatly appreciated: and Many thanks in advance

This is the method:

[ December 12, 2006: Message edited by: Joe Ess ]
 
Ulf Dittmer
Rancher
Posts: 43011
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Something like the following would create a collection of all lines:
 
jay lai
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ulf Dittmer ; I will try it out. Regards
 
jay lai
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ulf:
Okey, i have not work with reading file before, but it seems it read the file and adding into the Collection. As you mentioned, need to get the collection and loops through in jsp to display, I done with before with data from table, but not FILE. How do I loops through the collection of the lines and don't have a getter/setter. The method I wrote return a Collection , then I need to some how post it back to the browser ? I am very new to Spring, so trying to put things together step by step. Hopefully with your greatly help will resolve my difficulty and confused.
Many thanks

public ModelAndView handleRequest(
HttpServletRequest req,
HttpServletResponse res) throws Exception
{
return new ModelAndView("jbosslog", [should be the collection here???], param3)

}



[ December 13, 2006: Message edited by: Joe Ess ]
 
Ulf Dittmer
Rancher
Posts: 43011
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure how Spring does things, but normally you'd set the collection as a request attribute, so that the JSP could retrieve it and iterate through it.
 
jay lai
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again for trying to help! Regards
 
If you settle for what they are giving you, you deserve what you get. Fight for this tiny ad!
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!