I would like to have my Spring MVC application mapped to the following extension *html for jsp and *.action for controllers.
this is for login page:
@RequestMapping(value="/login.html", method=RequestMethod.GET)
public ModelAndView login(){
ModelAndView mv = new ModelAndView("login/login");
//omitted
return mv;
}
and this is for action:
@RequestMapping(value="/login.action", method=RequestMethod.POST)
public ModelAndView actionSignUp(@Valid User user){
//omitted
return mv;
}
and jsp is simple:
<form:form method="POST" action="/login.action" commandName="user" >
<form:input path="userName" id="userName" /><br />
<form:input path="password" id="password"/><br />
<input id ="login" type="submit" value="Login"></input>
</form:form>
my web.xml is the following:
<display-name>SpringMVC</display-name>
<servlet>
<servlet-name>springMVC</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springMVC</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>springMVC</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
<servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
I have no problem to get /login.html, but I have a problem with POST request on /login.action
I'm getting
HTTP Status 404 - /login.action
Why my mapping for *.action is not working?
Can I map two different extensions *html and *.action ?
The action method in your form was defined as action="/login.action"
. The / makes the url relative to your domain. You should notice that the form posted to a url similar to http://localhost:8080/login.action which should be http://localhost:8080/[context root]/[sub dir if defined]/login.action
I recon that removing the '/' will fix it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With