简体   繁体   中英

How to invoke a controller using a button in Spring-mvc?

I am using Spring MVC. I have a home page called index.jsp

<a href="register.htm"> Register an Employee</a>
<input type="button" onclick="register.htm" value="REGISTER">

When i click on a link Register an Employee , the flow comes into the handleRequest but when i click on submit button nothing happened.

My handleRequest method look like this.

@RequestMapping(value = "/register.htm", method = RequestMethod.GET)
    public ModelAndView handleRequest(HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        ModelAndView mav = new ModelAndView("register");
        return mav;     
    }

How i can do this?

尝试这个..

<input type="button"  onclick="location.href='/register.htm'" value="Register" >

location.href should be avoided as it uses RequestMethod.GET instead of RequestMethod.POST. This is security vulnerability if you use GET method to submit forms. Use the following example: http://www.mkyong.com/spring-mvc/spring-mvc-handling-multipage-forms-with-abstractwizardformcontroller/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM