• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Line number in servlet

 
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 " + ???);
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Bartender
Posts: 2856
10
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic