0

I'm working e-commerce store project using spring mvc. In a JSP login page, i need to check user name and user password after clicking submit button. If all information are ok then i'm gonna go to the next page, otherwise stay on the same page.

This is my Administrator class(Model) Administrator.java

@Entity
@Table(name="ADSMINISTRATOR")
public class Administrator {
    @Id
    private String userName;
    private String userPassword;
    //getter and setter 
}

This is my controller class AdministratorController.java

@Controller
@RequestMapping(value="/administratorController")
public class AdministratorController {
    @RequestMapping(value="/loginForm.html")
    public ModelAndView getAdministratorLoginForm() {
        return new ModelAndView("Administrator");
    }

    public ModelAndView goToMainPage(@ModelAttribute("administrator") Administrator administrator) {
        //Checking userName and userPassword here
        //if ok then
        return new ModelAndView("mainPageDemo");
    }

}

And this is my JSP(View) Administrator.jsp

<body>
    <table>
        <tr> <td>User Name: </td> <td><input type="text" name="userName" value="" placeholder="User Name"></input></td> </tr>
        <tr> <td>User Password: </td> <td><input type="text" name="userPassword" value="" placeholder="User Password"></input></td> </tr>
        <tr><td><input type="submit"></input></td> </tr>
    </table>
</body>
</html>

Now When I click submit button in Administrator.jsp page, I need to execute goToMainPage() method in AdministratorController.java class. How can i do this?

  • Possible duplicate of [How do I call a specific Java method on click/submit event of specific button in JSP?](http://stackoverflow.com/questions/14723812/how-do-i-call-a-specific-java-method-on-click-submit-event-of-specific-button-in) – Julian Aug 04 '16 at 18:28
  • You need to set up a form that will invoke the method when the button gets clicked, basically. – Julian Aug 04 '16 at 18:29
  • Also, your table name on the `Administrator` class `@Table(name="ADSMINISTRATOR")` seems wrong. `@Table(name="ADMINISTRATOR")` – Julian Aug 04 '16 at 18:30
  • Yes, table name was wrong and i'm tring by using servlet as you referenced. – B M Shams Nahid Aug 04 '16 at 18:34

0 Answers0