I am working on web application and trying to follow MVC design pattern. Now, I have almost all parts ready: Model and View. Right now in my View (JPS page) I decide how program flow should go. So, according to MVC I should move decision part to a Controller. Now, should a controller be a Servlet or just a Bean that talks between View and Model. If so, should the Servlet (Controller) be called from inside a JSP? If yes, how? I mean if I am going to use <jsp:forward="/servlet/controlServlet"> then how do I come back with data from Servlet into JSP page (View). I think I am confused...
All right brain, you don't like me and I don't like you, but let's just do this one thing so I can get back to killing you with beer.<br /> <br />- Homer Simpson
Following the standard Model 2 pattern (a rough approximation of MVC for web apps), your URLs should map to the servlet controllers, and not JSPs. The servlets do their thing, and then forward on to the JSP pages to render the view.
Right now I have my jsp page getting input from what button was pressed by user, so if I have Servlet Controller do that and Controller forwards output to JSP, after that step how can a servlet proccess next request if output had been forwarded to JSP and all controls have been left with a Servlet? Or should JSP have representations of controls but forward the actual values back to servlet for proccessing such as <jsp:forward page="/servlet/controlServlet?action=next">? [ July 20, 2004: Message edited by: Alex Kravets ]
after that step how can a servlet proccess next request if output had been forwarded to JSP and all controls have been left with a Servlet?
I have no idea what you are asking here.
The sequence is actually pretty simple:
1) When a URL is entered, the servlet gains control and performs whatever processing it needs to do. The servlet produces no response output.
In best case, the JSP contains noJava. JSTL tags and custom actions should be used in place of scriplets.
3) Once the page is rendered by the browser, the user initiates any action by selecting links or submitting forms, which brings us back to step 1. [ July 20, 2004: Message edited by: Bear Bibeault ]
Joined: Jan 24, 2001
ok, so the entry point is a Servlet, it proccess data and forwards to a JSP page, JSP page displays output from Servlet and as the second step and all steps after that submits to the Servlet, right?
Any info that the servlet needs to pass onto the JSP are stored (by the servlet) as request attributes which the JSP can easily retrieve.
Isn't this a lot of requests? [ July 20, 2004: Message edited by: Alex Kravets ]