2016-08-22 3 views
1

私は訓練生のjava-devです。これは私の最初の質問ですので、私を判断しないでください!春の別のコントローラーをリセットする

jspファイルで動作するControllerクラスがあります。最初のJSP(userinput.jsp)には、3つのテキストフィールド(lat、lon、radius)と2つのボタン(submit、デフォルト値を適用)があります。 2番目のJSPは、データ(ユーザー入力に依存する)と開始ボタン(userinput.jsp)に戻って既存のデータをすべて削除するリセットボタンで構成されるHTMLテーブルです。私はこれをどのようにするべきですか?

ボーナスの質問:2番目の状態(htmlテーブル)でページを更新しようとすると、ブラウザはすべてのデータを失うとの警告が表示され、更新しないでください。どうすればこれを取り除くことができますか?

@Controller 
@EnableAutoConfiguration 
class SpringBootController implements InitLogger { 

    @GetMapping(value="/geohash") 
    public String getUserInput(ModelMap model) { 
     model.put("command", new Tuple()); 
     return "UserInput"; 
    } 

    @PostMapping(value="/geohash", params="SubmitWithDefault") 
    public String defaultUserInput(ModelMap model) { 
     model.put("command", tupleFill (48.104564, 20.800041, 6)); 
     return "UserInput"; 
    } 

    @PostMapping(value = "/geohash", params="Submit") 
    public String printHash(@ModelAttribute("user")Tuple tuple,ModelMap model) { 
     GetData.setLat1(tuple.getFirstCoordinate()); 
     GetData.setLon1(tuple.getSecondCoordinate()); 
     GetData.setRad1(tuple.getRadius()); 

     LocationExecute.calculate(); 
     model.addAttribute("geoItemList", LocationExecute.getTupleList()); 
     model.addAttribute("listSize", LocationExecute.getTupleList().size()); 
     return "Geohash"; 
    } 

    @PostMapping(value = "/geohash", params="reset", method = RequestMethod.GET) 
    public ModelAndView method() { 
     return new ModelAndView("redirect:geohash"); 

    } 
} 

userinput.jsp - ボタン

<input type="submit" name="Submit" value="Submit" style="height:25px; width:100px"/> 
<input type="submit" name="SubmitWithDefault" value="Default Values" style="height:25px; width:100px"> 

geohash.jsp - (HTMLテーブル)リセットボタンあなたがPRG(ポスト-Redirect-を実装する必要が

<input type="reset" name="reset" value="Reset" style="height:30px; width:100px"> 

答えて

0

このようにそれを解決:

geohash.jsp (追加フォーム:フォームタグ)

<form:form action="/geohash"> 
    <th> <input type="submit" name="reset" value="Reset" style="height:30px; width:100px"> </th> 
    </form:form> 

コントローラ (投稿方法の変更)

@RequestMapping(value = "/geohash", params="reset", method = RequestMethod.POST) 
public ModelAndView method() { 
     return new ModelAndView("redirect:geohash"); 
} 
0

この問題を解決するためにMVCのデザインパターンを入手してください。 詳しく http://www.c-sharpcorner.com/UploadFile/dacca2/implement-prg-pattern-in-mvc-architecture/

ので、代わりにあなたがしたい場合は、ビュー名は、いくつかのデータは、その後春のflashAttributesを使用する方法をリダイレクトするために送信されるので、あなたの問題が解決され、それをリダイレクト返すために以下を通過してください

関連する問題