Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Line number in servlet

 
Naresh Chaurasia
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 " + ???);
 
Hongli Li
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Prasad Tamirisa
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Karthikeyan Ramaswamy
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic