I have a spring MVC application with following details
- war file name is forms.war. url pattern in web.xml is
"/"
- Controller action's @RequestMapping is
"/"
- RequestMethod.GET actions work properly if localhost:8080/forms is hit
- RequestMethod.POST actions not triggered if the post data is hit against
localhost:8080/forms
- The POST requests gives a 302 redirect
- When I hit
localhost:8080/forms/
the POST requests work properly
Any solution to make POST request work without trailing slash?
Here is the code I used to test the 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();
}
}
}
Changing the url to /forms/ works for POST request but not /forms
\@Controller public class JSONController { \@RequestMapping(value="/",method = RequestMethod.GET) public \@ResponseBody String handleGET(HttpServletRequest request) { } \@RequestMapping(value="/",method = RequestMethod.POST) public \@ResponseBody String handlePOST(HttpServletRequest request) { } }
– Elavarasu Pandiyan Mar 13 '17 at 12:42