我想将有效负载超过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>
当我尝试时,所有请求仅作为GET。我试过的时候
http://127.0.0.1:8080/Application_name/Servlet
然后它工作正常
答案 0 :(得分:0)
Servlet根据请求类型处理2种方法中的请求,其中只有一种:
的doGet 的doPost
你可以在你的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.....
}