我正在捕捉一个设备事件,并根据来自它的信息我需要进行登录。如果登录已验证,我想转到我的应用程序的下一页。执行一个servlet,以便我的doGet方法被调用
我试着用HttpURLConnection
来做,但它并没有真正执行servlet。
这是我使用的遗传密码:
public static String getResponseFromUrl(String url) throws Exception {
URL website = new URL(url);
HttpURLConnection connection = (HttpURLConnection)website.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("Content-Type", "application/json; charset=utf-8");
connection.setUseCaches(false);
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String response = "";
String inputLine;
while ((inputLine = in.readLine()) != null)
response += inputLine;
in.close();
return response.toString();
}
我也试过
InputStream responseInputStream = connection.getInputStream();
但具有相同的结果。 doGet
方法没有被调用,显然该应用程序不会移动到下一页。
我很确定这可以通过在JSP
页面内捕获事件来完成,但我希望有一个更简单的解决方案。
编辑:当在浏览器中提交相同的URL它一切正常。 doGet被调用并且应用程序移动到下一页。
doGet()not called mean doGet()not invoked或getResponseFromUrl()not invoke?或其他东西 –
getResponseFromUrl()被调用并且没有错误地运行。但doGet没有被调用。 – Eddy
这意味着在当时获取请求时doGet()没有被调用正确的时候开始?如果doGet not invoke意味着所有其他bla bla不执行。我正确的想法? –