aspose file tools*
The moose likes Beginning Java and the fly likes Line number in servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Line number in servlet" Watch "Line number in servlet" New topic
Author

Line number in servlet

Naresh Chaurasia
Ranch Hand

Joined: May 18, 2005
Posts: 356
I am using simple servlet,

What method can I use to return the current line number of my coding in the servlet?

Assuming I'm at line 10 and I want to do something like
System.out.println("I am at line number " + ???);


SCJP 1.4, SCWCD1.4, OCA(1Z0-007)
Hongli Li
Ranch Hand

Joined: Oct 29, 2006
Posts: 124
I don't know what's the purpose of doing it, but when you compile your java code you can enable debug so that when exception thrown it will tell you at which line you have problem.


Do you know why this cup is useful? Because it is empty.
Prasad Tamirisa
Ranch Hand

Joined: Mar 26, 2007
Posts: 130
What method can I use to return the current line number of my coding in the servlet?

what is the actual purpose of it? And in which case you are trying to use this..??
[ May 28, 2008: Message edited by: Prasad Tamirisa ]

Regards,
Durga Prasad
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2716
    
    6

There is no good reason for doing this I guess.

But you can do it manually by remembering the line numbers and saying



but why would someone want to do that?


SCJP, SCWCD.
|Asking Good Questions|
Karthikeyan Ramaswamy
Ranch Hand

Joined: Apr 30, 2008
Posts: 41
hi, lets try this

StackTraceElement[] st = Thread.currentThread().getStackTrace();
int lineNumber = st[st.length-1].getLineNumber();
System.out.println("lineNumber "+lineNumber);


----------------------------
Prasad Tamirisa
Ranch Hand

Joined: Mar 26, 2007
Posts: 130
Originally posted by Karthikeyan Ramaswamy:

StackTraceElement[] st = Thread.currentThread().getStackTrace();
int lineNumber = st[st.length-1].getLineNumber();
System.out.println("lineNumber "+lineNumber);


Nice one man. This should work. Really nice thought. It never striked my mind.
 
Don't get me started about those stupid light bulbs.
 
subject: Line number in servlet