title: How can I send form values from jsp file to controller in Spring, JSP?
body: <p>I'm trying to design a web page allows users to make comments on eachothers' profiles. To do this, the logged in user clicks the name of another user and see his/her detailed profile page and can make comment on that page. So the <em>Comment</em> table has two foreign key columns as <em>commentator_id</em> and <em>owner_id</em>. When a user makes a comment on another user's profile, the comment table will keep the both users' id and the text, title of comment and so on. </p>
  
  <p>Here's my <em>Controller</em> :</p>
  
  <pre><code> @RequestMapping(value = "/comment", method = RequestMethod.GET)
      public ModelAndView comment(Principal principal, String username, @ModelAttribute Comment c) {
  
          ModelAndView result = new ModelAndView("result");
  
          User user = userService.findByUsername(username); // the user who gets the comment
  
          String username2 = (String) ((Authentication) principal).getPrincipal(); //logged in user who makes the comment
          User authenticatedUser = userService.findByUsername(username2);
  
  
          c.setCommentator(authenticatedUser);;
          c.setOwner(user);
  
  
          user.getComments().add(c);
  
          userService.save(host);
  
          String message = "Com was successfully added.";
          result.addObject("message", message);
          return result;
  
      }
  </code></pre>
  
  <p>My <em>jsp</em> file : </p>
  
  <pre><code>&lt;body&gt;
    &lt;form method="post" action="comment"&gt;
              &lt;center&gt;
              &lt;table border="1" width="30%" cellpadding="5"&gt;
                  &lt;thead&gt;
                      &lt;tr&gt;
                          &lt;th colspan="2"&gt;Leave a referance&lt;/th&gt;
                      &lt;/tr&gt;
                  &lt;/thead&gt;
                  &lt;tbody&gt;
                  &lt;tr&gt;
                          &lt;td&gt;Title&lt;/td&gt;
                          &lt;td&gt;&lt;input type="text" name="title" value="" /&gt;&lt;/td&gt;
                      &lt;/tr&gt;
                      &lt;tr&gt;
                          &lt;td&gt;Text&lt;/td&gt;
                          &lt;td&gt;&lt;input type="text" name="message" value="" /&gt;&lt;/td&gt;
                      &lt;/tr&gt;
  
         // ...
  
                  &lt;/tbody&gt;
              &lt;/table&gt;
              &lt;/center&gt;
               &lt;a href="&lt;c:url value="/comment"&gt;&lt;c:param name="username" value="${user.getUsername()}"/&gt;&lt;/c:url&gt;"&gt;Send&lt;/a&gt;
                        &lt;/form&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>With this way, a user can make comment on another user's profile but the <em>Comment</em> table only keeps the id of both user but not the text, title and other values which I get from the form. How can I also keep form values in the db?</p>