File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes MVC without struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "MVC without struts" Watch "MVC without struts" New topic
Author

MVC without struts

Yash Sharma
Ranch Hand

Joined: Jan 30, 2003
Posts: 61
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 ]
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
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.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
sunitha reghu
Ranch Hand

Joined: Dec 12, 2002
Posts: 937
Yash,
Please check this tutorial. This will help you to start the work.
Yash Sharma
Ranch Hand

Joined: Jan 30, 2003
Posts: 61
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

Joined: Dec 12, 2002
Posts: 937
Did you read the tutorial?
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
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

Joined: Jan 30, 2003
Posts: 61
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.
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982

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


SCJP 1.2, OCP 9i DBA, SCWCD 1.3, SCJP 1.4 (SAI), SCJD 1.4, SCWCD 1.4 (Beta), ICED (IBM 287, IBM 484, IBM 486), SCMAD 1.0 (Beta), SCBCD 1.3, ICSD (IBM 288), ICDBA (IBM 700, IBM 701), SCDJWS, ICSD (IBM 348), OCP 10g DBA (Beta), SCJP 5.0 (Beta), SCJA 1.0 (Beta), MCP(70-270), SCBCD 5.0 (Beta), SCJP 6.0, SCEA for JEE5 (in progress)
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
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
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
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


SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
Ko Ko Naing
Ranch Hand

Joined: Jun 08, 2002
Posts: 3178
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 ]

Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
Nicholas Cheung
Ranch Hand

Joined: Nov 07, 2003
Posts: 4982
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

Joined: Jun 08, 2002
Posts: 3178
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

Joined: Nov 07, 2003
Posts: 4982
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
roul ravashimka
Ranch Hand

Joined: Mar 16, 2004
Posts: 53
front controller

Hope this helps,

Roul


MSc Electronics, ICT
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MVC without struts
 
Similar Threads
New application design
Interview
why struts a preferred MVC framework
Difference Between Architecture and Framework
struts2 Vs spring mvc