关于网友提出的“ http 405这个错误怎么弄啊”问题疑问,本网通过在网上对“ http 405这个错误怎么弄啊”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题: http 405这个错误怎么弄啊描述:
在书中找到一段代码,运行后,错误为
java.io.IOException: Server returned HTTP response code: 405 for URL: http://localhost:8080/EXES/Applet_servlet/servlet/DbServlet
代码主要是:先启动一个applet,然后再其中调一个servlet,
我想出问题的就是这一段了
String qryString = tfQuery.getText();
try {
/* The line below can be adjusted to your local servlet position */
URL url = new URL("http://localhost:8080/EXES/Applet_servlet/servlet/DbServlet");
String qry = URLEncoder.encode("qry") + "=" +
URLEncoder.encode(qryString);
URLConnection uc = url.openConnection();
uc.setDoOutput(true);
uc.setDoInput(true);
uc.setUseCaches(false);
uc.setRequestProperty("Content-type",
"application/x-www-form-urlencoded");
DataOutputStream dos = new DataOutputStream(uc.getOutputStream());
dos.writeBytes(qry);
dos.flush();
dos.close();
InputStreamReader in = new InputStreamReader(uc.getInputStream());
int chr = in.read();
while (chr != -1) {
taResults.append(String.valueOf((char) chr));
chr = in.read();
}
in.close();
} catch(MalformedURLException e) {
taResults.setText(e.toString());
} catch(IOException e) {
taResults.setText(e.toString());
}
结果就抛出异常了,查了查书,http 405表示 method not allowed,不准用的方法,Request-Line中指定的方法不准用于request-URI标识的资源。
请问大家,这个错误怎么改呀,能不能改啊