Web services 如何在java中直接发送HTTP POST

Web services 如何在java中直接发送HTTP POST,web-services,http,jakarta-ee,servlets,Web Services,Http,Jakarta Ee,Servlets,我想将负载超过255的HTTP POST请求发送到URL,如图所示 http://127.0.0.1:8080/Application_name ,它应该直接命中Servlet,为此我配置了web.xml,如下所示 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:javaee="http://java.sun.

我想将负载超过255的HTTP POST请求发送到URL,如图所示

 http://127.0.0.1:8080/Application_name
,它应该直接命中Servlet,为此我配置了web.xml,如下所示

    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:javaee="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" id="WebApp_ID" version="2.4">
   <welcome-file-list>
         <welcome-file>Servlet</welcome-file>
   </welcome-file-list>
 <servlet>
<servlet-name>Servlet_INTERFACE</servlet-name>
<servlet-class>com.app.package1.Servlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Servlet_INTERFACE</servlet-name>
<url-pattern>/Servlet</url-pattern>
</servlet-mapping>
</web-app>
那么它的工作很好

  • 可能吗
  • 如果是,我怎么做
  • 别名是一种解决方案吗

  • Servlet使用两种方法处理请求,根据请求类型,仅使用其中一种方法:

    多吉特 多波斯特

    您可以在servlet中编写如下内容:

    public void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException 
    {       
     ......GET CODE.....
    }
    
    public void doPost(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException 
    {       
    ......POST CODE.....
    }
    

    如果总是使用GET,那么问题很可能出在您的客户身上。你能用你的http客户端代码更新这个问题吗?你使用的是什么容器(这曾经是tomcat的一个bug)?是否尝试在欢迎文件定义:/Servlet中添加尾随斜杠?
    public void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException 
    {       
     ......GET CODE.....
    }
    
    public void doPost(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException 
    {       
    ......POST CODE.....
    }