Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet simple web applications using log4j

Have Programming Question? Ask it here!
 
 
 


sujitha
simple web applications using log4j
2 Answer(s)      2 years and 5 months ago
Posted in : JSP-Servlet


i am getting java.lang.NoClassDefFoundError: org/apache/log4j/Logger and javax.servlet.ServletException: Error instantiating servlet class Sample exceptions when trying to execute. this is my code.............. public class Sample extends HttpServlet {

private static Logger logger= Logger.getLogger("Sample.class");   

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    PrintWriter out =response.getWriter();
    out.println(" hello sujitha");
    try
    {
        logger.info("info level");
    }
    finally
    {

    }
}

Advertisement
View Answers

February 7, 2012 at 12:51 PM


Have a look at the following link:

Log4j Tutorials



February 29, 2012 at 12:21 PM


Log4j webapplication - servlet,log4j.xml

   // Program by Nishanth Thomas ‚?? Insolutions Global Bangalore

  // example  class file   

 package com.logs;


  import java.io.IOException;
  import java.text.SimpleDateFormat;
  import java.util.Date;

  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpSession;

  import org.apache.log4j.BasicConfigurator;
  import org.apache.log4j.FileAppender;

  import org.apache.log4j.Logger;
  import org.apache.log4j.PatternLayout;

  import org.apache.log4j.PropertyConfigurator;
  import org.apache.log4j.xml.DOMConfigurator;


public class Logscollected {


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

   public static void logscollection(Exception e,       HttpServletRequest request) throws IOException{


      HttpSession session = request.getSession();

              String  exceptiondetail = ‚??‚?? ;

//create a folder in your application config and place  log4j.xml file there  and       

  // get path by the following;

      String strPath =  request.getRealPath("config");

      DOMConfigurator.configure(strPath+"/"+"log4jexp.xml");

        //create log4j.xml file as give name like  shown above log4jexp;

  try{

      ////  /* Get the Stack Trace messages //////

    e = ((e==null)?((Exception)request.getAttribute("Exception")):e);

        StackTraceElement stem[]=e.getStackTrace();

        for(int i=0;i<stem.length;i++){


      if (!exceptiondetail.equals(""))

          exceptiondetail += "\n";

          exceptiondetail += "\t";

               exceptiondetail=exceptiondetail+stem[i].toString();
        }

          log.debug(exceptiondetail);
                  //log.info(e);
                    // log.warn("Here is some WARN");
                    //  log.info(object);
          log.error(e);

          //  log.fatal("Here is some FATAL");

    }catch(Exception e1){
        e1.printStackTrace();
    }
  }

}

In the catch of any servlet call that function like this

       try{

    //     Some code‚?¶‚?¶‚?¶‚?¶

      }

    catch(Exception e)
        {

                    // Logs collection log 4j------------------------

            Logscollected.logscollection(e,request);

        //---------------------------

}

Finally log4j config file

Lo4j.xml here we renamed to log4jexp.xml to avoid conflicts with server log4j.xml file palce log4jexp.xml in config folder ( here I used)


<--configure path according to your requrmts to save log file -->

<!--code  between <log4j:configuration>  </log4j:configuration>  -->  

<appender name="daoAppender" 
   class="org.apache.log4j.RollingFileAppender">   
    <param name="maxFileSize" value="100KB" />   
    <param name="maxBackupIndex" value="2" />   
    <param name="File" value="${jboss.server.home.dir}/deploy/myexampleprj.war/serverlogs/serverlogs.txt" />   
    <layout class="org.apache.log4j.PatternLayout">   
        <param name="ConversionPattern"  
               value="%d{dd-MMM-yyyy HH:mm};%5p %c %m%n" />   
    </layout>   
</appender>   

  <--configure path according for diff packge to your requrmts to save log file -->   

<!--appender name="appAppender"  
          class="org.apache.log4j.RollingFileAppender">   
    <param name="maxFileSize" value="100KB" />   
    <param name="maxBackupIndex" value="2" />   
    <param name="File" value="${jboss.server.home.dir}/deploy/myexampleprj.war/serverlogs/serverlogs.txt" />   
    <layout class="org.apache.log4j.PatternLayout">   
        <param name="ConversionPattern"  
               value="%d{ABSOLUTE} %5p %c{1}: %m%n " />   
    </layout>    
</appender-->   

<!‚??package name given in category here com is the package give package name  -->    

<!--category name="com.ex.actions">     
    <priority value="DEBUG"/>     
    <appender-ref ref="appAppender"/>       
</category-->
<category name="com">     
    <priority value="DEBUG"/>     
    <appender-ref ref="daoAppender"/>       
</category>    

<root>   
    <!--     
    <appender-ref ref="appAppender" />   
    <appender-ref ref="daoAppender" />   
    -->    
</root>



Related Tutorials/Questions & Answers:
simple web applications using log4j
simple web applications using log4j  i am getting java.lang.NoClassDefFoundError: org/apache/log4j/Logger and javax.servlet.ServletException: Error instantiating servlet class Sample exceptions when trying to execute. this is my
log4j in web application
log4j in web application  Hi all, I am new to log4j. I want to use log4j in my web application. I need to write the debug,info,warn into a file... and how to get the logger object in web application. Thanks suresh
Advertisements
Simple Web Application using Servlet
Simple Web Application using Servlet       In this section, we have developed a simple web... a web page ("addUser.jsp")  to add the new user.    
Log4j
Log4j  what is the use of log4j in realtime?   Please visit the following link: Log4j Tutorials
log4j
log4j  explain about log4j with example ?   Please visit the following link: log4j Tutorials
Compression of rolled-over files using log4j
Compression of rolled-over files using log4j  How can I use log4j to rollover the log files on hourly basis and compress the rolled over files
Log4J Tutorials: Using Log4J in Easy Steps
Log4J Tutorials: Using Log4J in Easy Steps Log4j is a logging library for Java.... One of the major advantages of using Log4j is that it arranges the log output... Architecture A simple example of log4j Use of BasicConfigurator in Log4j logging
Log4J - Log4J
Log4J  What is the use of Log4j? where does it use? Log4j is using for debuging ur code. Its does the same thing as System.out/System.err do. i.e to trace out ur program   Log4j is using for debuging ur code.Its does
developing simple web service
: The Web Services Invocation Framework (WSIF) is a simple Java API...Open Source web services tool in java   .../ About Axis: Apache Axis is an implementation of the Simple Object
log4j - Log4J
log4j  could u pls help me out regarding the log4j coding   http://www.javaworld.com/javaworld/jw-12-2004/jw-1220-toolbox.html Thanks
Top 10 Web Applications
to take advantage of developing new applications using its API, etc. On web you...When new and newer range of web based applications are virtually changing our... to choose a list of top 10 web applications. The choice is huge and similar
log4j - Log4J
log4j  give me explanation about log4j,junit? how i hvae to use them   Hi mamatha, In Log4J, if you log a message at DEBUG level, and the current Appender is set to only log messages of INFO level and above
Java Building a Simple Web Service ? A Tutorial Tutorial
in designing and developing enterprise class web applications using JAVA and J2EE... Building a Simple Web Service ? A Tutorial... In this tutorial we will create a simple web service and a client web application
Internationalization and Localization of Web Applications in Java
Internationalization and Localization of Web Applications in Java... applications in java. Localization of Web applications means that a web.... Internationalization of Web applications means that a web application that is created
how to design control panel for web applications
how to design control panel for web applications  how to design control panel for web applications
how to communicate with different web applications - JSP-Servlet
how to communicate with different web applications  how to communicate with different web applications which are under same or different servers? ex... to second/jsp/show.jsp without using query string like that can u guide me how
JBoss Seam - Web 2.0 Applications
web applications with simple annotated Plain Old Java Objects (POJOs...JBoss Seam - Web 2.0 Applications      ... generation Web 2.0 applications. It unifies and integrates technologies
How to communicate with different web applications ? ? ? ? - JSP-Servlet
How to communicate with different web applications ? ? ? ?  Deepak ji... with different web applications which are under same or different servers? ex.../show.jsp without using query string like that In your answer display.jsp
*** How to communicate with different web applications ? ? ? ? - JSP-Servlet
*** How to communicate with different web applications ? ? ? ?  ... to communicate with different web applications which are under same or different servers? ex.../show.jsp without using query string like that In your answer display.jsp
How to communicate with different web applications ? ? ? ? - JSP-Servlet
How to communicate with different web applications ? ? ? ?  How to communicate with different web applications which are under same or different... to second/jsp/show.jsp without using query string like that can u guide me how
* How to communicate with different web applications ? ? ? ? - JSP-Servlet
* How to communicate with different web applications ? ? ? ?  Deepak... with different web applications which are under same or different servers? ex.../show.jsp without using query string like that In your answer display.jsp
Simple application using hibernate
Simple application using hibernate  Hi, How to write a simple application using hibernate in Eclipse IDE? I would like to to learn: Process... of the tutorial you will like to learn for creating the simple application using
How Traditional Web Applications Works
How Traditional Web Applications Works         How traditional web... web applications and then in the next section we will explore the working
Hibernate Logging using Log4j
This section contains detail description of how you can use Log4j for logging configuration
Characteristics of simple Web 2.0 Website
Characteristics of simple Web 2.0 Website       Before making any Web 2.0 site, the programmers must... is the fundamental thing. The web designers should have to design a very simple, sober
Regarding Simple Web service example - WebSevices
Regarding Simple Web service example  hi i am trying to follow the simple web service example in the tutorials and it develops the application in Netbeans IDE using the GlassFish Server . however when i did the same
Web 2.0 Characteristics,Web 2.0 Applications,Web 2.0 Conference,Web 2.0 Tools,Web 2.0 Technologies,Web 2.0 Techniques
using Web 2.0 is different. Some uses it accidentally as for browsing purpose. Some... Web 2.0 Characteristics       Characteristics of Web 2.0 Though there is a controversy still going
Use of BasicConfigurator in Log4j logging
In this part of tutorial we will tell you how to configure log4j using... Use of BasicConfigurator in Log4j logging       log4j warning log4j: WARN No appenders could
Simple banking system using Java
Simple banking system using Java  I am trying to make a simple... and the other is the branch, the third interface is the main class. Using inheritance the branch is supposed to inherit the activities of the main office...using
Log4J Architecture - Introduction to the Log4J architecture
. Configuring Log4J For running application using Log4J you need.... There are two ways to configure the Log4J one is by using properties file and other by using xml file. Using xml for Log4J is quite popular and it is recommended
java - Log4J
, an OutputStream, a java.io.Writer etc. Using Log4j it is possible to enable logging... regarding "LOG4J" and where these are exactly used in realtime application and purpose of using this,thanks in advance,i hope i may get reply for this as soon
Simple HTML example
Simple HTML example In this section we will give you very simple example of a HTML page. After reading this page you should be able to create simple HTML pages for your website. HTML is used to create web pages for websites. You
Log4j error - Log4J
Log4j error  Error while running tomcat server. SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.util.Log4jConfigListener java.lang.NoClassDefFoundError: org
Configuring Log4J
Configuring Log4J  Is it possible to configure xml file in such a way that it has different logging levels for diferent packages in java through Log4J
log4j - Java Interview Questions
log4j  plz send me example program, using log4j and tel me how to execute that program.(what are the requirements to execute that program
Building Search Engine Applications Using Servlets !
Building Search Engine Applications Using Servlets Introduction... programmers writing web applications. What you should know? You should have... using Java Servlets. You can Download the source code of search
hi - Log4J
hi  Please give me the clear definition of Log4J and give me the example
java - Log4J
java  Q What is the real use for log4J?  Hi Friend, Please visit the following link: http://www.roseindia.net/tutorials/log4j/index.shtml Thanks
simple web appllication to insert, update or display from database - JSP-Servlet
simple web appllication to insert, update or display from database  hello sir i am using netbeans 5.5 ide with tomcat and oracle 9 i as database. can you please send one example with code to how to cerate web application
Difficulty in plugging log4J with Hibernate.
Difficulty in plugging log4J with Hibernate.  I am using Hibernate 3.6. Followed your all instruction of plugging log4j with my hibernate code... HandlingWorker, it uses SLF4j and does not detect log4J. What could
Hibernate log4j
Hibernate log4j  Hi, when i run the FirstExample.java given in the tutorial, i got the right output, what my doubt is from where i am getting the log4j messages, like log4j:WARN no appenders could be found for logger
Using JMeter for a Simple Test
Using JMeter for a Simple Test       Lets see how to run JMeter now. We will conduct a simple test... on which the Web applications run which is usually 80.   Protocol
Hibernate Simple Program Using Java Application with Eclipse
Hibernate Simple Program Using Java Application with Eclipse  How to write Hibernate Simple Program Using Java Application with Eclipse? I wish to learn Hibernate using very popular Eclipse IDE. Share me the best tutorial link
Developing Simple Web Service
Developing Simple Web Service     ... developing web services with Axis2 by an easy example ?HelloWorldService? and deploying it on the tomcat web server. Step 1: Build Axis2 Web
How JSF Fits For Web Applications?
How JSF Fits For Web Applications?      JSF best suits in to the java web development environment... existing frameworks that makes it a better choice for web application
Building a Simple EJB Application Tutorial
enterprise class web applications using JAVA and J2EE technologies. He currently... EJB and a client web application using eclipse IDE along with Lomboz plug...Building a Simple EJB Application - A Tutorial   
jsp - Log4J
path to set servlet programs   What is the path to set servlet programs ?  Use the following path to set servlet programs while using weblogic serverprojectfolder -> WEB-INF -> classes -> MyServlet.java
prog. using radio buttons for simple calculator
prog. using radio buttons for simple calculator  import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; class Calculator extends JFrame { private final Font BIGGER_FONT = new Font
prog. using radio buttons for simple calculator
prog. using radio buttons for simple calculator  import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; class Calculator extends JFrame { private final Font BIGGER_FONT = new Font
Why Web Services?
will understand why Web Services are developed and what are the benefits of using Web Services for  the development of  Enterprise applications. Why Web Services? Here are the benefits of using Web Services: Exposing
Advertisements
 

 

 

DMCA.com