File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes MVC Pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "MVC Pattern" Watch "MVC Pattern" New topic
Author

MVC Pattern

Rakesh Keerthi
Ranch Hand

Joined: Jul 16, 2012
Posts: 144
Hi,

i have the below jsp which i want to divide into MVC(as adviced by Bear previously as the best practice. and thank you for that bear), i am unable to understand what goes unde Model, View and Controller.

please help me with it.

Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

you didnt employee servlet or servlet filter or some kind of controller . and here jsp is doing all the work .

in MVC, you need to define one role to one worker. normally
*JSP-best suite for view(should only contain logic for view).
*Servlet[known as controller]-he is good at delegating request to appropriate location/business logic.
*Java class-Obviously better to put your logic here.

So that, specialized people can concentrate their job with out interfering others.
and for example: jsp is best place to put html , view logic etc..
if you put their java class then it wont be convenient to maintain
[working in java code in java class is better than working in java code in jsp is in IDE]
and there are many reason why MVC is famous...
=> WhyNotUseScriptlets

and now you move all your business logic(java code) to java class and call the class from your servlet, hence submit your form/jsp to servlet
Rakesh Keerthi
Ranch Hand

Joined: Jul 16, 2012
Posts: 144
Thank you seetharaman. i'll do it.
Vijay kumarIdbi
Greenhorn

Joined: May 14, 2012
Posts: 4
Hi Rakesh,

Venkatasamy is correct but if you want you can put one more layer between your servlet and Logic layer that will be good
In this layer you just provide the manipulations you want to do with your data and logic layer will only give you the
output of the query.In this way your last layer will be unplugged any time if you want to change your databas query or
type etc. In that you just have to remove the last layer in this .If you put any manupulations with data then it will be
very dependent on that layer.
Is it clear for you or just i confuse you more..Please reply.

Thanks.
Rakesh Keerthi
Ranch Hand

Joined: Jul 16, 2012
Posts: 144
Hi Vijay,

Thank you for the reply, It is a bit confusing, but, according to my understanding you say to seperate even DB logic from servlet and use it so that DB manuplation can be even more easy. please correct me if i'm wrong. if i'm right i'll proceed as you say.

Thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61437
    
  67

Have you read this article?

A JSP is part of the view, so it cannot be part of the model or controller.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MVC Pattern