aspose file tools*
The moose likes Servlets and the fly likes MVC implementation? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "MVC implementation?" Watch "MVC implementation?" New topic
Author

MVC implementation?

satish chander
Greenhorn

Joined: Dec 21, 2009
Posts: 12
how to apply MVC pattern practically using tomcat . I know theoretically that what is MVC but not able to implement it.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60082
    
  65

Welcome to the Ranch. Two things to help you out:

1) Please be sure to take the time to compose descriptive subjects for your posts; read this for more information. A title such as "please help me out" is not helpful. What would happen if all posts had such a title?

Please go back and change your post to add a more meaningful subject by clicking the button on your post.

2) Please do not ask for answers in email. Keep any discussion within the forums. Please read this for more information.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

M- Model
V-View
C- Controller

write a plain java class as a Model , servlet as a controller and Presentation code in JSP.

Model:-Model is responsible for providing the data from the database and saving the data
into the data store. All the business logic are implemented in the Model. Data entered by
the user through View are check in the model before saving into the database. Data
access, Data validation and the data saving logic are part of Model.

View:-View represents the user view of the application and is responsible for taking the
input from the user, dispatching the request to the controller and then receiving response
from the controller and displaying the result to the user. HTML, JSPs, Custom Tag
Libraries and Resources files are the part of view component.


Controller: Controller is intermediary between Model and View. Controller is
responsible for receiving the request from client. Once request is received from client it
executes the appropriate business logic from the Model and then produce the output to
the user using the View component.

structure of files in Tomcat (create a directory in webapp say MyApp)

MyApp
|
.jsp
.html
WEB-INF(directory)
|
web.xml
classes(directory)-This folder contains your .class files


Life is easy because we write the source code.....
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

The easiest way to implement it is to use an existing MVC framework; there are several.

If you're interested in implementing MVC itself I'd first read any of hundreds of references available on the web that describe it in its various forms.
satish chander
Greenhorn

Joined: Dec 21, 2009
Posts: 12
thanks pramod ...
i will try making this but is it compulsary to make index file if yes then how can i use it in this context (MVC)
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

It is not compulsary to make index file, but it is good if you have it.
when you enter URL in the browser and if requested resource is not present in your application then instead of giving HTTP 404 error message you can display that page (i.e. index.html or index.jsp). For this you have to configure welcome pages in web.xml like..


<web-app>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>


Place this index.html in your root directory of application.

suppose you have folloowing directory structure

MyApp
|
.jsp
.html (You can put your index.html here)
WEB-INF(directory)
|
web.xml
classes(directory)-This folder contains your .class files

when you enter following URL in browser then index.html will be displayed:
http://localhost:8080/MyApp/

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I'm not aware that an welcome file would be used for a 404--I'm pretty sure it won't.
xsunil kumar
Ranch Hand

Joined: Dec 14, 2009
Posts: 129
David, you are right, welcome file is not for providing UI incase of HTTP 404 error. It is used when you have opened application without any extension means you have provided URL address like 127.0.0.1:8080/<Context Path>.

In this case welcome file will come in picture. Its not related to 404 error any where if requested resource is not present .

-Sunil
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

error-page [Define in web.xml] element should use for 404 error
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

Yes you are right David it's my fault.Thanks.....
Aj Deschanel
Ranch Hand

Joined: Oct 20, 2009
Posts: 40
satish chander wrote:how to apply MVC pattern practically using tomcat . I know theoretically that what is MVC but not able to implement it.

Read chapter 3 of HeadFirst Servlets & JSP (Mini MVC Tutorial) ... you will get it in 30 minutes.


SCJP 1.6, SCWCD 1.5
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MVC implementation?
 
Similar Threads
How to implement google map in spring mvc portlet
Implementing Bredcrums in spring MVC
Patterns question
Struts selection
WA #1.....word association