war文件名是forms.war。 web.xml中的url模式为"/"
控制器操作的@RequestMapping为"/"
如果遇到localhost:8080 /表单,则RequestMethod.GET操作正常工作
如果针对localhost:8080/forms点击发布数据,则不会触发RequestMethod.POST操作
POST请求提供302重定向
当我点击localhost:8080/forms/时,POST请求正常工作
醇>
任何使POST请求工作而不尾随斜杠的解决方案?
以下是我用来测试POST api的代码:
public class HttpPostExample {
public static void main(String[] args) {
HttpClient httpClient = HttpClientBuilder.create().build();
try {
HttpPost request = new HttpPost("http://localhost:8080/forms");
StringEntity params =new StringEntity("{\"form_url\":\"admin\",\"website\":\"US_WEBSITE\",\"email\":\"testelascrip1@gmail.com\",\"cis_name\":\"testscrip1\"} ");
request.addHeader("content-type", "application/x-www-form-urlencoded");
request.setEntity(params);
HttpResponse response = httpClient.execute(request);
System.out.println("Printing the response code " + response.getStatusLine().getStatusCode());
} catch (IOException e) {
e.printStackTrace();
}
}
}
将URL更改为/ forms /适用于POST请求但不适用于/ forms