简体   繁体   中英

Spring basic form error 405

Hi i got this error try to learn some of Spring Java framrework. I got an 405 - Request method 'POST' not supported and i need some help to see what is my error on this

my controller

@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;

    }

 }

and this is my form 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>

and the 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>

I try to understand what is worng. The controller creates an object site adding the info form the form an then the otrer .jsp renders the new object created...

You have to specify your form action to correspond the method in your controller : admin/addNewSite.

The 405 error tells you that the form action is unknown.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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