title: How to set the value of an html input field in java?
body: <p>I have two files.
  An .html that contains a <code>&lt;input type=&quot;text&quot;&gt;</code> and a .java that contains java methods.
  In a java method I need to set the value of that html input.
  What is the code to do that?</p>
  <p>Here is the code I have.</p>
  <p>View</p>
  <pre><code>&lt;form action=&quot;personform&quot; method=&quot;post&quot; th:object=&quot;${personBind}&quot;&gt;
  &lt;input type=&quot;text&quot; name=&quot;name&quot; th:field=&quot;*{name}&quot;&gt;
  &lt;input type=&quot;text&quot; name=&quot;year&quot; th:field=&quot;*{year}&quot;&gt;
  </code></pre>
  <p>Spring MVC Controller</p>
  <pre><code>ModelAndView modelAndView = new ModelAndView(&quot;Person.html&quot;);
  modelAndView.addObject(&quot;personBind&quot;, person);
  return modelAndView;
  </code></pre>
  <p>The value in the name field comes from the person object in the modelAndView.
  That works fine.
  But the value for the year field is not in the person object.
  I want to set the value in the year field coming from a different source.
  What code should I write to set the value in the year field?</p>