Servlet 停止,没有给出任何异常

发布于 2024-08-27 07:16:23 字数 3020 浏览 3 评论 0原文

我已经在 Mandriva Linux 上的 Tomcat 6 服务器上实现了托管的 Servlet。我已经能够让客户端与Servlet进行通信。为了响应请求,Servlet 尝试实例化位于同一目录中的另一个类(名为 KalmanFilter)。卡尔曼滤波器尝试创建四个矩阵(使用 Jama Matrix 包)。但此时 Servlet 停止了,没有给出任何异常!

但是,从同一目录中的另一个测试代码,我已经能够创建 KalmanFilter 类的实例,并继续执行,不会出现任何错误。仅当我的 Servlet 尝试实例化 KalmanFilter 类并创建矩阵时,才会出现此问题。有什么想法吗?

以下是代码:

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()");       
}               
}

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()");       
}               
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风吹雨成花 2024-09-03 07:16:23

如果您从 servlet 中删除了 try/catch 块,那么诊断起来会更容易。此代码抛出的唯一已检查异常是 IOException,而 doGet 允许您抛出该异常,而无需自己捕获它。

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");                
}  

这样,异常将显示在浏览器上,而不是消失在日志文件中。当然,这对于用户来说并不是很好,但是对于您的开发来说,它让生活变得更轻松。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文