开发者

Submit button doesn't submit

In my Spring application when i click on the submit button on my form reloads the page, i'm sure i had forgotten something but i can't see the error

In the jsp, I'm creating the form like this:

        <form:form commandName="municipioBean" method="POST">
            <label for="df_mun">Estado</label>
            <form:select path="df_edo" name="df_edo" id="df_edo"
                onchange="getMunicipios();">
                <form:option value="0">Seleccione un estado...</form:option>
                <form:options items="${listaEstado}" itemValue="codProvincia"
                    itemLabel="desProvincia" />
            </form:select>

            <label for="df_mun">Municipio</label>
            <form:select path="df_mun" name="df_mun" id="df_mun">
                <option selected value="0">S开发者_如何学JAVAeleccione un estado primero...</option>
            </form:select>

            <form:hidden id="id_ciudadano" path="id_ciudadano" />
            <input type="submit" name="procesar" value="Aceptar" />
        </form:form>

And my controller:

@RequestMapping(method = RequestMethod.POST, params = "procesar")
public String procesaSubmit(
        @ModelAttribute("municipioBean") MunicipioBean municipioBean,
        BindingResult result, HttpServletRequest request, ModelMap model) {


    return ConstantesAbre.PASOS_JSP;
}

Params value is equal to the name of my submit button and the RequestMethod it's ok too, what's the problem?.

Thanks in advice and sorry for my bad english D:


You need to add a value in your @RequestMapping usually the name of the page.

For example

@RequestMapping(method = RequestMethod.POST, params = "procesar", value="/theJspName")

I usually set up my controllers with the base path decalred at the top of the class like this:

 @Controller
@RequestMapping("/main")
public class MainController {


@RequestMapping(method = RequestMethod.POST, params = "procesar", value="/theJspName")
public String procesaSubmit(@ModelAttribute("municipioBean") MunicipioBean municipioBean,        BindingResult result, HttpServletRequest request, ModelMap model) {    
  return ConstantesAbre.PASOS_JSP;
}

So your full path would be something like http://server:port/application/main/theJspName

There could also be an extension depending on how you set up your ViewResolver.

Also make sure that you have

<context:annotation-config/>
<context:component-scan base-package="your package here"/>

<mvc:annotation-driven/>

defined somewhere in your app-servlet.xml or applicationContext.xml file.

Hope that helps a little.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜