源自:1-3 手工编写第一个Servlet

get方法没问题,post方法报405错误

HTTP Status [405] – [Method Not Allowed]

Type Status Report

Message HTTP method POST is not supported by this URL

Description The method received in the request-line is known by the origin server but not supported by the target resource.

Apache Tomcat/9.0.0.M21

代码:index.jsp:

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

html>

">

Insert title here

第一个servlet小例子


Get方法请求HelloServlet

HelloServlet.java:package servlet;

import java.io.IOException;

import java.io.PrintWriter;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

public class HelloServlet extends HttpServlet {

@Override

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

// TODO Auto-generated method stub

System.out.println("处理Get请求……");

PrintWriter out = response.getWriter();

response.setContentType("text/html;charset=utf-8");

out.println("Hello Servlet");

}

@Override

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

System.out.println("处理Post请求……");

PrintWriter out = response.getWriter();

response.setContentType("text/html;charset=utf-8");

out.println("Hello Servlet");

}

}

web.xml:<?xml  version="1.0" encoding="UTF-8"?>

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns="http://xmlns.jcp.org/xml/ns/javaee"

xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"

version="3.1">

index.jsp

HelloServlet

servlet.HelloServlet

HelloServlet

/servlet/HelloServlet

提问者:Tsukiis

2017-06-06 14:22

java get请求405_get方法没问题,post方法报405错误相关推荐

  1. 解决Fiddler不能监听Java HttpURLConnection请求的方法

    在默认情况下,Fiddler不能监听Java HttpURLConnection请求.究其原因,Java的网络通信协议栈可能浏览器的通信协议栈略有区别,Fiddler监听Http请求的原理是 在应用程 ...

  2. httpposterror_http请求405错误方法不被允许的解决 (Method not allowed)

    由于自己疏忽,导致请求错误405,然后前端数据传输没错,百度大都说跟post提交方式有关,改成get还是报错,检查才知道,controller中忘记写@requestMapping("/XX ...

  3. webservice 405 java_用浏览器测试Get与Post Webservice,Post一直报405错误,而Get能够成功的原因与解决方法...

    楼主在用Jersey开发Restful Webservice的时候碰到了这样一个问题 同样一个方法实现,用@get定义和@post定义,@get能通过测试,而@post不能 @GET //@POST ...

  4. 通过java.net.URLConnection发送HTTP请求的方法

    2019独角兽企业重金招聘Python工程师标准>>> 1.GET与POST请求的区别 a) get请求可以获取静态页面,也可以把参数放在URL字串后面,传递给servlet, b) ...

  5. java的connect和http_【JAVA】通过URLConnection/HttpURLConnection发送HTTP请求的方法

    Java原生的API可用于发送HTTP请求 即java.net.URL.java.net.URLConnection,JDK自带的类: 1.通过统一资源定位器(java.net.URL)获取连接器(j ...

  6. java获取请求ip的方法

    在上篇文章中我们介绍了 java获取请求 ip的方法,那么这篇文章我们就来详细讲解下获取请求 ip的方法.获取请求 ip的方法是基于 HTTP协议的,其原理如下: 1.用 web应用程序,将 web服 ...

  7. 信息: 解析 HTTP 请求 header 错误 java.lang.IllegalArgumentException: 在方法名称中发现无效的字符串, HTTP 方法名必须是有效的符号.

    信息: 解析 HTTP 请求 header 错误 Note: further occurrences of HTTP request parsing errors will be logged at ...

  8. java 判断请求为 ajax请求_Java过滤器处理Ajax请求,Java拦截器处理Ajax请求,java 判断请求是不是ajax请求...

    Java过滤器处理Ajax请求,Java拦截器处理Ajax请求,拦截器Ajax请求 java 判断请求是不是ajax请求,Java判断是否为ajax请求 >>>>>> ...

  9. Java过滤器处理Ajax请求,Java拦截器处理Ajax请求,java 判断请求是不是ajax请求

    Java过滤器处理Ajax请求,Java拦截器处理Ajax请求,java 判断请求是不是ajax请求 Java过滤器处理Ajax请求,Java拦截器处理Ajax请求,拦截器Ajax请求 java 判断 ...

最新文章

  1. Spring Boot配置文件 application.properties
  2. 20211104 为什么矩阵的迹等于特征值之和,为什么矩阵的行列式等于特征值之积
  3. UTC时间、GMT时间、本地时间、Unix时间戳
  4. mysql udf安全_打造全功能MYSQL入侵UDF
  5. 春晚鬼畜 B 站日排行最高,赵本山:我的时代还没有结束!
  6. linux第一课历史与未来方向
  7. 12306微信小程序上线 提供余票查询暂不支持购票
  8. 扫雷游戏网页版_借“买量”造爆款,梦幻西游网页版击穿H5游戏天花板
  9. matlab 多属性权重,多属性决策的权重确定方法及matlab 程序
  10. POJ 2387 Til the Cows Come Home BFS最短路求解
  11. php 邮箱附件 大小限制,Exmail+Postfix修改邮件附件大小
  12. WinKawaks详尽使用说明
  13. cadence、PADS、protel教程(PCB Layout图文教程终结版)
  14. Failed to decode response: zlib_decode(): data error Retrying with degraded;
  15. Android 端app直播源代码,解决系统启动黑屏
  16. CISSP-OSG-各章节书面实验整理
  17. HTML DOM nextSibling 和nextElementSibling属性
  18. 几款强大的PPT制作辅助软件
  19. 基于camunda如何实现会签:camunda会签流程配置与原理解析
  20. [BluehensCTF 2022] pwn11 crypto3

热门文章

  1. UEStudio中进行文件编码转换
  2. java rar_java如何解压rar文件
  3. Linux系统ssd硬盘擦除,如何实现安全擦除 _固态硬盘小Z聊固态-中关村在线
  4. c++文件保存与读取
  5. 使用tensorflow:LSTM神经网络预测股票(三)
  6. Linux简介,linux终端符号含义
  7. html当前窗口打开页面,JavaScript 在本窗口打开网页
  8. 如何在Oracle官网下载JDK8u202
  9. rono在oracle的作用_sqlnet.ora的作用
  10. 三个步骤教你如何通过天猫精灵控制智汀,实现不同生态设备相互联动