• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

MVC without struts

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not an expert on web technology and want to implement MVC pattern for a web-based application of mine. But due to a steep deadline I would be unable to learn and use Struts (atleast for now). Can anyone please help me by pointing to some tutorial/code examples that guides on rolling ones's own simple MVC application using HTML, JSP and Servlets/Beans. .P.S.This app of mine would also interact with a database
[ May 19, 2004: Message edited by: Yash Sharma ]
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First, you need to decide whether you want to use a single Front Controller servlet (like Struts' ActionServlet) or multiple servlets (typically one per each logical action). Then, simply enforce the rule that each HTTP request must be handled by a servlet (or the servlet in case of Front Controller) and that these servlets must delegate any processing to some kind of business logic classes.
 
Ranch Hand
Posts: 937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yash,
Please check this tutorial. This will help you to start the work.
 
Yash Sharma
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Sunitha! but is the link you gave on MVC design pattern?
Thanks Lasse, is there any good tutorial on it?
 
sunitha reghu
Ranch Hand
Posts: 937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you read the tutorial?
 
Lasse Koskela
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Yash Sharma:
Thanks Lasse, is there any good tutorial on it?


Probably yes, but it's a bit difficult to find them since Google will most likely give you "recent" articles first, which most likely cover existing MVC frameworks instead of building your own...
 
Yash Sharma
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes Sunitha I did read the link you provided which is based on a pattern that uses JSP as the controller and not Servlets (not MVC I suppose). I could lay hands on one here but this seems to be too old a tutorial.

Lasse, you are correct in saying that Googling would not help which is what I did before posting my question here. A mere mention of MVC would lead you to unending list of resources on using Struts but none on how could you roll a simple MVC framework of your own.
 
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Yes Sunitha I did read the link you provided which is based on a pattern that uses JSP as the controller and not Servlets (not MVC I suppose). I could lay hands on one here but this seems to be too old a tutorial.


NO. The pattern that uses JSP as the controller is ALSO a MVC pattern.

In the very very beginner, the MVC pattern used in JSP and Servlets DID use JSP as the controller, this is the MVC model I.

After then, people found that JSP is not good to be the Controller, and then people try using Servlet as the Controller, which is known as MVC model II.

Ko Ko has told me this before.

Nick
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Personally, I think MVC is only a pattern, and pattern should be adopted by different technolgoies, not only binded to any technologies.

Thus, for whatever systems and programming languages, once your system has objects that centralize the control flow, objects that responsible to hold data, and objects that know how to process the objects with data, then, the system can be regarded as using MVC pattern.

Take my SCJD assignment as an example.

SCJD requires only Java applications, which means, we dont have JSP, Servlets, EJB, etc.

But still, I can work out a system that using MVC patterns. I have a data object that stores data obtained from the Database (data file).

The client can only interact with the GUI, and the GUI contains only a JTable (for displaying data records), and some textfields and buttons to perform search and update.

When the user highlights a record in JTable, and click update, this request has been received by the ActionListener, and then sent to the control object, named GUIController, this controller determines what to do, and send a request to the server (DB) to update the data.

After updating the data, the server sends back the data objects with the updated values, and the controller passes the data objects to view, which it then converts the data objects into a form that the JTable knows how to display them.

Thus, without Struts, JSP, Servlets and EJB, the system can still apply the MVC pattern.

Nick
 
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
MVC Architecture

separate core business model functionality from the presentation and control logic that uses this functionality. Such separation allows multiple views to share the same enterprise data model, which makes supporting multiple clients easier to implement, test, and maintain.



http://java.sun.com/blueprints/patterns/MVC-detailed.html
http://java.sun.com/blueprints/guidelines/designing_enterprise_applications_2e/web-tier/web-tier5.html
 
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Nicholas Cheung:

NO. The pattern that uses JSP as the controller is ALSO a MVC pattern.

In the very very beginner, the MVC pattern used in JSP and Servlets DID use JSP as the controller, this is the MVC model I.

After then, people found that JSP is not good to be the Controller, and then people try using Servlet as the Controller, which is known as MVC model II.

Ko Ko has told me this before.

Nick



Yes, I did... It's was from the very first chapters of SCWCD Exam Study Kit...

BTW, Nick, ur SCJD assignment looks excellent... I missed ur success story about SCJD. How many scores did you shoot it to SCJD Exam?
[ May 20, 2004: Message edited by: Ko Ko Naing ]
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I lost many scores in GUI and Locking parts, the rest parts, including OO design, general consideration, documentation, etc score perfect.

Thus, I am confident to say that MVC pattern does not bind to any technologies, as even I do not use JSP/Servlets/EJB/Struts, I can have the same effect.

But just, of course, making use of Struts make life easier, as the workflow has already been built-in, what we need to do is the configuration, not the algorithm implementation.

Nick
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Nicholas Cheung:
what we need to do is the configuration, not the algorithm implementation.


Yes, you are right, Nick... We, Computer Science guys, know how tough is algorithm design, comparing to configuring this and that in a framework... Struts makes life easier... But we also need to think about the adjustment between small projects and configuration stuff in Struts, as we also have such discussion in another thread...
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thus, whether MVC with or without Struts is depends.

For non-Web-bsaed applications, I think they cannot use Struts, as Struts engine needs to be stayed with the container. Thus, we may need to have own only controller (at least) to control the workflow. If the systems are small and simple enough (like SCJD), you may find it interesting, as you can try writing something similar to Struts, but if the system is complex, you definitely find it is painful.

For Web-based applications, I guess no matter how small or how large it is, Struts is a good choice, as we dont need to write any specific controller, and we can make good use of the existing technologies.

Nick
 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
front controller

Hope this helps,

Roul
 
reply
    Bookmark Topic Watch Topic
  • New Topic