Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring MVC 3.0 mapping extension

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 ?

like image 948
danny.lesnik Avatar asked Nov 14 '22 00:11

danny.lesnik


1 Answers

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.

like image 59
gouki Avatar answered Nov 16 '22 15:11

gouki