How to Pass Html Input value(Html Form) to java controller ? - Spring MVC

Viewed 13626

I want to use normal Html tags with Spring MVC instead of spring Html tags but I am unable to get the input value to Controller using simple html tags.

Below is my Code:-

Controller :

@Controller
public class LoginService {

    @RequestMapping(value = "/authenticate", method = RequestMethod.GET)
    public String authenticateUser(Model model,@ModelAttribute("userName") String userName, 
            @ModelAttribute("password") String password) {
        System.out.println("coming in controller    " +userName +" : "+ password);  
        model.addAttribute("message", "Hello Spring MVC Framework!");
        return "success";
    }

JSP :

<body>
<h2>${message}</h2>
<form action="authenticate.htm">
    <table>
        <caption>
            <h3>Enter Your Login Credentials</h3>
        </caption>
        <tr>
            <td>User Name</td>
            <td><input type="text" id="userName"></input></td>
        </tr>
        <tr>
            <td>Password</td>
            <td><input type="password" id="password"></input></td>
        </tr>
        <tr rowspan="2">
            <td><input type="submit"></input></td>
        </tr>
    </table>
</form>

web.xml

   <servlet>
      <servlet-name>HelloWeb</servlet-name>
      <servlet-class>
         org.springframework.web.servlet.DispatcherServlet
      </servlet-class>
      <load-on-startup>1</load-on-startup>
   </servlet>

   <servlet-mapping>
      <servlet-name>HelloWeb</servlet-name>
      <url-pattern>*.htm</url-pattern>
   </servlet-mapping>
1 Answers
Related