2017-10-22 68 views
-1

嗨,我得到这个错误尝试学习一些Spring Java framrework。 我得到一个405 - 请求方法“POST”不支持,我需要一些帮助,看看有什么是我对这个春季基本形式错误405

错误我控制器

@Controller 
@RequestMapping("overcomandant/addSitio.asp") 
public class addSitioController { 

    @RequestMapping(method = RequestMethod.GET) 
    public ModelAndView addSitioForm() { 

     ModelAndView asf = new ModelAndView(); 
     asf.setViewName("admin/addNewSite"); 
     asf.addObject("sitio", new Sitio()); 

     return asf; 
    } 

    @RequestMapping(value="admin/addNewSite", method = RequestMethod.POST) 
    public String addSitioSubmit(Sitio st, ModelMap model) { 

     model.addAttribute("url", st.getUrl()); 
     model.addAttribute("nombre", st.getNombre()); 
     model.addAttribute("estado", st.getEstado()); 

     return "admin/exito"; 

    } 

    @ModelAttribute("estadoLista") 
    public Map<String,String> ListadoEstados() { 

     Map<String, String> estado = new LinkedHashMap<>(); 
     estado.put("1","Activo"); 
     estado.put("2","Inactivo"); 
     estado.put("3","Testing"); 

     return estado; 

    } 

} 

,这是我的形式addNewSite.jsp

<form:form method="POST" commandName="sitio"> 

       <div class="form-group"> 
       <form:label path="id">ID</form:label> 
       <form:input path="id" cssClass="form-control"/> 
       </div> 

       <div class="form-group"> 
       <form:label path="url">URL</form:label> 
       <form:input path="url" cssClass="form-control"/> 
       </div> 

       <div class="form-group"> 
       <form:label path="nombre">Nombre</form:label> 
       <form:input path="nombre" cssClass="form-control"/> 
       </div> 

       <div class="form-group"> 
       <form:label path="estado">Estado</form:label> 
       <form:select path="estado" cssClass="form-control"> 
        <form:option value="0">Seleccione</form:option> 
        <form:options items="${estadoLista}" /> 
       </form:select> 
       </div> 

        <input type="submit" value="Enviar" class="btn btn-primary" /> 

      </form:form> 

和exito.js

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<%@page contentType="text/html" pageEncoding="UTF-8"%> 
<!DOCTYPE html> 
<html> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
     <title>JSP Page</title> 
    </head> 
    <body> 
     <h1>Hello World!</h1> 

     <p><c:out value="${url}"></c:out></p> 

    </body> 
</html> 

我试图了解为w ORNG。 控制器创建一个对象网站添加信息形式的表单然后otrer .jsp呈现新的对象创建...

+0

如果您的问题得到解决,请考虑接受答案。 –

+0

我来了一个交叉与addNewSite.jsp在窗体标记的答案我想把操作参数这样一些事情和问题解决就像你告诉我做的=) – wecbxxx

回答

1

您必须指定您的表单动作以对应您的控制器中的方法:admin/addNewSite。

405错误告诉您表单操作未知。