2016-11-21 14 views
1

こんにちは私はこのコントローラで有線の動作をしています。送信後の@RequestMapping(method = RequestMethod.POST)は、HTTPステータス405 - リクエストメソッド 'POST'を取得しました

コントローラー:

@Controller 
public class NotificationController { 

    final String JSP_NOTIFICATION_01="pages/sendPush/createNotification"; 
    final String JSP_NOTIFICATION_02="pages/sendPush/createNotificationStep2"; 


    @RequestMapping(value ="/admin/notification/newNotification",method = RequestMethod.GET) 
    public String newNotification(Map<String, Object> model, HttpServletRequest request) { 

     //prepare info to fill html form 

     request.getSession().setAttribute("notificacion", notification); 
     return JSP_NOTIFICATION_01; 
    } 


    @RequestMapping(value ="/admin/notification/sendNotification", method = RequestMethod.POST) 
    public String saveNotification(@ModelAttribute("notForm") SendNotificationModel notForm, 
             Map<String, Object> model,HttpServletRequest request) { 


     //Get all information from HTML form 

     System.out.println("llego.."+resultado); 

     model.put("resultado", resultado); 

     return JSP_NOTIFICATION_02; 
    } 
} 

JSP

 <form:form action="${pageContext.request.contextPath}/admin/notification/sendNotification" method="post" commandName="notForm"> 
       <form:hidden path="clientName" /> 
       <form:hidden path="clientCode" /> 
      </tr> 
      <tr> 
       <td>topics:</td> 
       <td><form:select path="topics" items="${topicList}" /></td> 
      </tr> 
      <tr> 
       <td>users:</td> 
       <td><form:select multiple="true" path="users" items="${userList}" /></td> 
      </tr> 
      <tr> 
       <td>Tipo de despliege :</td> 
       <td><form:select path="tipoNotificacion" items="${tipoNotificacionList}" /></td> 
      </tr> 

     </table> 
      <tr> 
       <td colspan="2" align="center"><input type="submit" value="Enviar" /></td> 
      </tr> 
     </table> 

    </form:form> 

後にPOSTメソッドを提出私は2つの方法がデ提出取得するには、HTMLフォームとPOSTで表示する情報を準備するには、Getしていますいつものようにリクエストを受け取りますが、リターンスプリングの後に405エラーが表示されます:

HTTP Status 405 - Request method 'POST' not supported 
type Status report 
message Request method 'POST' not supported 
description The specified HTTP method is not allowed for the requested resource. 

私はSpring 4.1.3とtomcat8を使用しています

ありがとうございました!!!

+0

をリダイレクトを入れて、リファレンスhttp://howtodoinjava.com/spring/spring-mvc/spring-mvc-display-validate-and-submit-form-example/

を動作するにはどのような違いを生むでしょうか?あなたはPOSTメソッド – koutuk

+0

@koutukに正確なパラメータを提供していることを確認してください間違ったパラメータが原因で405が発生するのはなぜですか? –

答えて

1

削除@RequestMapping(値= "/管理/通知/ sendNotificationを")コントローラ

+0

申し訳ありませんが、クラス内でグローバルなRequestMappingを使用して、各メソッドで分離しようとしました –

1

から注釈@RequestMappingクラスおよびメソッドレベルの両方で使用することができます。クラスレベルで使用すると、すべてのメソッドに適用されます。例えば以下のコードを見てください。

@Controller 
@RequestMapping("/appointments") 
public class AppointmentsController { 
    private final AppointmentBook appointmentBook; 
    @RequestMapping(method = RequestMethod.GET) 
    public Map<String, Appointment> get() { 
     return appointmentBook.getAppointmentsForToday(); 
    } 
    @RequestMapping(path = "/{day}", method = RequestMethod.POST) 
    public Map<String, Appointment> getForDay(@PathVariable @DateTimeFormat(iso=ISO.DATE) Date day, Model model) { 
     return appointmentBook.getAppointmentsForDay(day); 
    } 
} 

上記のコントローラコード/アポイントは相対的であり、以下のすべての方法に適用されます。メソッドの開始時に@RequestMappingが相対パスに追加されます。ただし、@RequestMappingはクラスレベルでは必須ではありません。さらなる理解のため、以下の公式文書を参照してください。 http://docs.spring.io/spring/docs/current/spring-framework-reference/html/mvc.html

1

成功(GET)メソッドを1つ追加して固定しました。 POSTメソッドでは、私は

@RequestMapping(value ="/admin/notification/sendNotification", method = RequestMethod.POST) 
public String saveNotification(@ModelAttribute("notForm") SendNotificationModel notForm, 
            Map<String, Object> model,HttpServletRequest request) { 

    NotificationDetails newNot = new NotificationDetails();//(NotificationDetails)request.getSession().getAttribute("notificacion"); 

    String resultado= "Probando" ; 
    System.out.println("llego.."+resultado); 

    model.put("resultado", resultado); 

    return "redirect:/admin/notification/sendNotification/success"; 
} 


@RequestMapping(value = "/admin/notification/sendNotification/success", method = RequestMethod.GET) 
public String success(Model model) 
{ 
    return JSP_NOTIFICATION_02; 
} 
関連する問題