我有在 JBOSS 中运行的服务器。有一个监听所有请求,即所有请求都到达过滤器并从这里Filter传递给其他请求。Servlets我注意到了这一点:
当我使用以下代码时,仅调用了过滤器,但控制权没有传递给相应的 Servlet(当我使用 打印时,过滤器打印正确的 servlet request.getRequestURI()。它还打印请求标头的正确值username和password)
HttpURLConnection connection=gs.getconnection("send_user_detail");
connection.setRequestProperty("user", gs.get_login_id());
connection.setRequestProperty("password", gs.get_pass());
connection.setRequestProperty("timezone", TimeZone.getDefault().getDisplayName());
connection.connect();
但是当我使用下面的代码时,控件会传递给相应的Servlet并且工作正常。
HttpURLConnection connection=gs.getconnection("send_user_detail");
connection.setRequestProperty("user", gs.get_login_id());
connection.setRequestProperty("password", gs.get_pass());
connection.setRequestProperty("timezone", TimeZone.getDefault().getDisplayName());
//connection.connect();
ObjectOutputStream out=new ObjectOutputStream(connection.getOutputStream());
out.writeObject("string"); //some random string not used in the servlet
因此,只有当我在 OutputStream 上写一些东西时,控制才会传递给 servlet。但是connection.connect(),它仍然上升到过滤器,甚至打印出请求的正确名称Servlet。是什么原因?