Home Answers Viewqa JSP-Servlet simple web applications using log4j

 
 


sujitha
simple web applications using log4j
2 Answer(s)      a year and 4 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
    {

    }
}
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 Pages:
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 - 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
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
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
log4j
; A simple example of log4j This Example shows you how... Log4J Tutorial - Log4J Examples in Java       In this tutorial you will learn about Log4J
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
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
L4j in WebApplication with common logging - Log4J
log4j for Web Application in which common logging api used i tried to configure... Property Configure code to add appender i think not because we are using... but it is not working.i am writting follwing code to cinfigure my log4j in my servlet
Developing responsive Ajax based Applications with ajax technologies
to help the developers to quickly construct the Ajax based web applications. You... of Web Application Development In the early days the web pages were static, simple HTML web pages, later on it became dynamic by using CGI script (Perl was mostly
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
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
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 is not logging even under src path
log4j is not logging even under src path  We are working with struts application and using log4j.properties file , it is placed under WEB-INF/classes and we have referenced log4j-1.2.8.jar in classpath file even after
A simple example of log4j for Servlet
A simple example of log4j for Servlet       This Example shows you how to create a log... passed as a string argument to a string by using appropriate object renderer
A simple example of log4j
A simple example of log4j   ... as a string argument to a string by using appropriate object renderer of class... or not, if yes then it converts the massage passed as a string argument to a string by using
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
Applications and Applets
Applications and Applets       Now a days, Java is widely used for applications and applets. The code... and is executed by a run-time interpreter. Applications are stand alone and are executed
* 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
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 ? ? ? ?  ... 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 ? ? ? ?  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
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
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
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   
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
Applications and Applets
Applications and Applets       Now a days, Java is widely used for applications and applets. The code... and is executed by a run-time interpreter. Applications are stand alone and are executed
Web Service Components
Web Service Components         Web service has three main components... Simple Object Access Protocol (SOAP) is a communication protocol
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
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
WriterAppender in Log4j
WriterAppender in Log4j     ... in simple file (plain/text) file and to the console also. If we want to write... of WriterAppender and since it requires Writer or OutputStream we are using a file "
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
log4j
log4j  explain about log4j with example ?   Please visit the following link: log4j Tutorials
Log4j
Log4j  what is the use of log4j in realtime?   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
remove logging - Log4J
? log4j hss been used for logging purpose.Thanks and regards vishal  hi...;? reporting technology for use in J2EE applications. It allows developers to create rich, dynamic applications and delivers highly-interactive, professional-looking
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
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
Hibernate Logging using Log4j
This section contains detail description of how you can use Log4j for logging configuration
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
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
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
Web Services
realistic examples built using the web services are heterogeneous applications... the clients are either the applications or the programs using the printers. Likewise... standardized set of  web services can be summarized by using an equation. Web Services
spring rmi - Log4J
spring rmi   HI, iam using eclipse for developing spring based rmi application. my problem is whenever a method is called in a server the log should be maintained and after finishes the execution of a method then again the log
Web 2
the development of web-sites that copy personal computer applications like (M.S.... applications The new feature included in the Web 2.0 based application in which... on a server using the HTTP verbs GET, POST, PUT, and DELETE. SOAP (Simple
L4j in WebApplication with common logging - Log4J
configure log4j for WebApplication  configure log4j for WebApplication  Hello,I seems that log4j.properties file is missing in your... of the web application.Hope this will solve your problem. Don?t forgot to update your
Deploy enterprise applications into servers
Deploy enterprise applications into servers Prev Chapter 6. Assemble enterprise applications...; Deploy enterprise applications into servers Installing
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
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
Web Services - Web Services Tutorials
to the remote source. One can access Web services using nothing but HTTP. Of all... platforms tend to agree on. Thus , using Web services, a Web service developer can... distributed applications - using radically different tools provided by many different
Web 2.0 Innovations
Web 2.0 Innovations       Innovations associated with ?Web 2.0? Web-based applications and desktops... to methods of publishing via using dynamic content management but web services