开发者

Servlet stops without giving any exception

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(){
    Sys开发者_运维知识库tem.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()");       
}               
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜