2013-06-03 36 views
3

當我填寫然後發送一個表單:表格價值發送,我不能初始化表單,即使通過重置按鈕。而且我總是被迫手動清空它。發送後重置表單 - 彈簧MVC

請問我該如何解決這個問題?

回答

3

這是解決方案,例如這是我們的形式:

<form:form action="/add" commandName="cmd" method="get"> 

控制器必須像這樣定義:

@RequestMapping(value="/add",method = RequestMethod.POST) 
    public String AddActivity(@ModelAttribute BeanClass cmd ,ModelMap model){ 
     //Here we have operations we want to do with this cmd 
      // Add an empty cmd to the controller at the end 
      model.addAttribute("cmd",new BeanClass); 

    } 
0

我不太瞭解mvc,但你應該可以用html中的按鈕來重置表單。在表單中包含以下內容。

<input type="reset" value="Reset!"> 
+0

如果這不起作用,請提交您的代碼,以便我們可以更好地幫助你。 – h4ck3r

+0

我試過重置按鈕它不工作,因爲表單被鏈接到ModelAttribute。但是,我發現解決問題的一個方法是在發送後由控制器向頁面添加新的ModelAttribute。 – Somar