Can't implement MVC properly in JSP
Posted on 2004-10-14
i am trying to use MVC in my JSP application. For every job to be done I have 3 pages, one for view , one for model and one for controller. Say i have an html form (form1.html) which the user fills and submits. This form goes to the controller (servlet1.java) which calls a java class, Model (model1.java) to perform database operations and business logic and the request is dispathed to the view (jsp1.jsp).
Similarly, If user enters a query to search in form2.html, it goes to servlet2.java which calls model2.java and then dispatches request to jsp2.jsp to display the result to the user.
In this way if I have say 10 forms, then i'll have 10 jsp's , 10 servlets and 10 models, names of each model and view hard coded into the servlet.
I know this is not the right way to do it. So many controllers and hard coded names of servlets and jsps make it look weird. There must be a better way of doing it.
I somewhere read Struts can be used to solve this problem. But at the moment i can't learn Struts. is there any way i can use just Servlets and JSP to solve this problem and get a better OO in my application.