3

我正在使用 Spring MVC。我有一个主页叫index.jsp

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

当我点击一个链接Register an Employee时,流程进入handleRequest但当我点击提交按钮时没有任何反应。

我的 handleRequest 方法看起来像这样。

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

我怎么能这样做?

4

2 回答 2

26

尝试这个..

<input type="button"  onclick="location.href='/register.htm'" value="Register" >
于 2012-10-23T10:42:18.173 回答
1

应避免使用 location.href,因为它使用 RequestMethod.GET 而不是 RequestMethod.POST。如果您使用 GET 方法提交表单,这是一个安全漏洞。使用以下示例: http ://www.mkyong.com/spring-mvc/spring-mvc-handling-multipage-forms-with-abstractwizardformcontroller/

于 2014-06-24T09:26:30.040 回答