Note that there are some explanatory texts on larger screens.

plurals
  1. POspring process POST data - annotate the right controller
    primarykey
    data
    text
    <p>I'm having problems with configuring spring MVC to process form POST data in the right controller. I've got an <code>add</code> action which is going to add a new record to the database.</p> <p>After the form is submitted, I'm getting 404 error (<code>http://localhost:8084/lyricsBase/song/submit.html</code>), so I guess that I've made something wrong in routing the form submission.</p> <p>This is my controller code:</p> <pre><code>public class SongController extends MultiActionController { [...] @RequestMapping(value = "/song/submit.html", method = RequestMethod.POST) public ModelAndView submit(@RequestParam("song") Song song) throws Exception { HashMap model = new HashMap(); model.put("song", song); // or do something better here... return new ModelAndView("t.edit", model); } </code></pre> <p>and this is the view form tag:</p> <pre><code>&lt;form:form method="POST" commandName="song" action="submit.html"&gt; </code></pre> <p>The code of my application is available on <a href="https://github.com/tkoomzaaskz/lyricsBase/tree/5a00efb733a87a9b3c8fa7dda084176ff7cb33b5" rel="nofollow">github</a>. Here are the important files: <a href="https://github.com/tkoomzaaskz/lyricsBase/blob/5a00efb733a87a9b3c8fa7dda084176ff7cb33b5/src/main/webapp/WEB-INF/jsp/edit.jsp" rel="nofollow">the form view</a>, the <a href="https://github.com/tkoomzaaskz/lyricsBase/blob/5a00efb733a87a9b3c8fa7dda084176ff7cb33b5/src/main/java/com/blogspot/symfonyworld/lyricsbase/controller/SongController.java" rel="nofollow">controller</a> (the class is a multi controller, since I don't want to create a separate file for each action) and <a href="https://github.com/tkoomzaaskz/lyricsBase/blob/5a00efb733a87a9b3c8fa7dda084176ff7cb33b5/src/main/webapp/WEB-INF/lyricsBaseApp-servlet.xml" rel="nofollow">servlet configuration</a>.</p> <p>Don't know if it matters, but I'm using tiles for the view layer (and logical view names are used in <a href="https://github.com/tkoomzaaskz/lyricsBase/blob/5a00efb733a87a9b3c8fa7dda084176ff7cb33b5/src/main/resources/tiles.xml" rel="nofollow">tiles.xml</a>).</p> <p>Besides, I don't fully understand how spring routing works. Until now, I'm defining a mapping in the servlet xml, but don't know if it is a good approach...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload