This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.



Only 44 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to call logger class in jsp file  RSS feed

 
Ramasubramaniam Rathinasubbu
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,

I am using log4j in my web application.

in java class i can call ,

but in jsp how can i call the Logger class
and how can i call log.info("hi ");



 
Ravishanker kumar
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can call logger on jsp as well. Just import required java classes on jsp using import page directive as below,

and use logger.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Modern JSPs should have no java code in them. Logging should not be necessary.
 
Ramasubramaniam Rathinasubbu
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes i am using same thing

in java

import org.apache.log4j.Logger;

static Logger log = Logger.getLogger(CandidateQuery.class);

then we are calling

log.info("hi");
log.Error("hi");
like that

but inside the jsp file

how can i call the log.info();


 
Harpreet Singh janda
Ranch Hand
Posts: 317
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the same code in JSP inside the scriptlets.
 
Ramasubramaniam Rathinasubbu
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks,

how can i call

<%@ page import="org.apache.log4j.Logger" %>
<%
static Logger log = Logger.getLogger("jspname");
log.info("hi");

%>

you are telling like this. If i call like this it saying error.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow. The time to be putting Java code in JSPs ended in 2002.
 
Harpreet Singh janda
Ranch Hand
Posts: 317
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What error?
Try with non static logger object.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!