简体   繁体   English

如何使用Spring-mvc中的按钮调用控制器?

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

I am using Spring MVC. 我正在使用Spring MVC。 I have a home page called index.jsp 我有一个名为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. 当我点击Register an Employee的链接时,流程进入handleRequest但是当我点击提交按钮时没有任何反应。

My handleRequest method look like this. 我的handleRequest方法看起来像这样。

@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. 应该避免使用location.href,因为它使用RequestMethod.GET而不是RequestMethod.POST。 This is security vulnerability if you use GET method to submit forms. 如果您使用GET方法提交表单,则这是一个安全漏洞。 Use the following example: http://www.mkyong.com/spring-mvc/spring-mvc-handling-multipage-forms-with-abstractwizardformcontroller/ 使用以下示例: http//www.mkyong.com/spring-mvc/spring-mvc-handling-multipage-forms-with-abstractwizardformcontroller/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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