I tried enter code here` @RequestMapping(value = "/test", method = RequestMethod.POST) but is error Code is
@Controller
public class HelloWordController {
private Logger logger = LoggerFactory.getLogger(HelloWordController.class);
@RequestMapping(value = "/test", method = RequestMethod.POST)
public String welcome() {
logger.info("Spring params is welcome");
return "/WEB-INF/jsp/welcome";
}
}
web.xml is
<servlet>
<description>This is Spring MVC DispatcherServlet</description>
<servlet-name>SpringMVC DispatchServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<description>SpringContext</description>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:springmvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<servlet-mapping>
<servlet-name>SpringMVC DispatchServlet</servlet-name>
<url-pattern>/</url-pattern>
and springmvc.xml is index.jsp is
<form action="<%=request.getContextPath() %>/test" method="post">
<input type="submit" value="submit">
</form>
I input submit botton brower is error HTTP Status 405 - Request method 'GET' not supported type Status report message Request method 'GET' not supported description The specified HTTP method is not allowed for the requested resource (Request method 'GET' not supported).
CodePudding user response:
GetRequest and PostRequest(which you mentioned on your code) is different things so you must use getRequest if you want your code to supply the data but not receive it
CodePudding user response:
Change
@RequestMapping(value = "/test", method = RequestMethod.POST)
to
@RequestMapping(value = "/test", method = RequestMethod.GET)