views:

44

answers:

1

Hi, I have implemented a Servlet hosted on Tomcat 6 server on Mandriva Linux. I have been able to make the client communicate with the Servlet. In response to a request the Servlet tries to instantiate a another class (named KalmanFilter) located in the same directory. The KalmanFilter tries to create four Matrices (using Jama Matrix package). But at this point Servlet stops without giving any exception !

However, from another test code in the same directory I have been able to create instance of KalmanFilter class, and proceed without any error. The problem occurs only when my Servlet tries to instantiate the KalmanFilter class and create the matrices. Any idea?

Below are the codes:

MyServlet.java

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class MyServlet extends HttpServlet {   
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
    doGet(request, response);
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException{  
    PrintWriter out = null;  //response.getWriter();    
    try{                            
        System.out.println("creating new KalmanFilter");
        KalmanFilter filter = new KalmanFilter();                       
        out = response.getWriter(); 
        out.print("filter created");                
    }catch(Exception ex){  
        ex.printStackTrace();
        System.out.println("Exception in doGet(): " + ex.getMessage());
        ex.printStackTrace(out);
    } 
}  
}

KalmanFilter.java

import Jama.Matrix;

public class KalmanFilter {

protected Matrix X, X0;
protected Matrix F, Q;
//protected Matrix F, B, U, Q;
protected Matrix H, R;
protected Matrix P, P0;

private final double EPSILON = 0.001;

public KalmanFilter(){
    System.out.println("from constructor of KalmanFilter");
    createInitialMatrices();                
}

private void createInitialMatrices(){
    System.out.println("from KalmanFilter.createInitialMatrices()");

    double[][] pVals = {
            {1.0, 0.0},
            {0.0, 1.0}
        };

    double[][] qVals = {
            {EPSILON, EPSILON},
            {EPSILON, EPSILON}
        };

    double[][] hVals = {
            {1.0, 0.0},
            {0.0, 1.0},
            {1.0, 0.0},
            {0.0, 1.0}
        };

    double[][] xVals = {
            {0.0},
            {0.0},
        };

    System.out.println("creating P Q H X matrices in createInitialMatrices()");

    try{
        this.P = new Matrix(pVals);
        System.out.println("created P  matrix in createInitialMatrices()");
        this.Q = new Matrix(qVals);
        System.out.println("created Q  matrix in createInitialMatrices()");
        this.H = new Matrix(hVals);
        System.out.println("created H  matrix in createInitialMatrices()");
        this.X = new Matrix(xVals);
        System.out.println("created X  matrix in createInitialMatrices()");
        System.out.println("created P Q H X matrices in  createInitialMatrices()");
    }catch(Exception e){
        System.out.println("Exception from createInitialMatrices()"+ e.getMessage());
        e.printStackTrace();
    }
    System.out.println("returning from createInitialMatrices()");       
}               
}
+1  A: 

It would make things easier to diagnose for you if you removed the try/catch block from the servlet. The only checked exceptions thrown by this code is IOException, and doGet allows you to throw that without catching it yourself.

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException{  
    System.out.println("creating new KalmanFilter");
    KalmanFilter filter = new KalmanFilter();                       
    out = response.getWriter(); 
    out.print("filter created");                
}  

That way, the exception will be displayed on the browser, rather than disappearing into a log file. Of course, this isn't very nice for the user, but for your development, it makes life easier.

skaffman
thanks for your answer. I tried the way you suggested. In the client side IOException is sent. But when I chacked the log (catalina.out) I see that after the line> System.out.println("creating P Q H X matrices in createInitialMatrices()");the remaining code didn't executed in the KalmanFilter class. I need to know why such happens, so that I can devise remedy. Even the catch block in KalmanFilter.java doesn't show any exception to have occured. I am really puzzled ! :(
Fahim
Oh I found ClassNotFoundException.java.lang.ClassNotFoundException: Jama.Matrix at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1516) at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1361) at KalmanFilter.createInitialMatrices(KalmanFilter.java:65) at KalmanFilter.<init>(KalmanFilter.java:38)I am using Jama, which came as a jar file, which I put in the 'classes' directory where the servlet class file is kept. I also added the jar file to my class path.What's wrong have I done? Should I keep the jar file somewhere else?
Fahim
ok I solved it, by putting the jar file in Tomcat's lib directory. Thanks to all.
Fahim