aspose file tools*
The moose likes Tomcat and the fly likes Problem deploying MVC with Tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Problem deploying MVC with Tomcat" Watch "Problem deploying MVC with Tomcat" New topic
Author

Problem deploying MVC with Tomcat

Gabriele Sturmer
Greenhorn

Joined: Apr 22, 2010
Posts: 1
Hello everybody. I am doing a project that requires me to implement a simple Model-View-Controller on my web server that uses Tomcat 5.5. The files that I am using are the ControllerServlet class, PersonBean class, and two jsp files hello.jsp and goodbye.jsp. The MVC we are supposed to implement is the one on this webpage:http://www.informit.com/guides/content.aspx?g=java&seqNum=117
I have already compiled my classes but now do not know where to upload all of these files on my web server. The two class files are in the package com.informit.webtechnologies. I have tried contacting my professor and fellow classmates and nobody has gotten their MVC to work yet. I am completely new to this and am taking my first web design class, which at our school gives us a week to learn each language. I would appreciate anyone who can simplify this process for me. Thanks
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Like any basic web applications, these classes should be kept under your WEB-INF/classes folder. If you package them in a JAR file, you can put the JAR file under WEB-INF/lib.


[My Blog]
All roads lead to JavaRanch
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16055
    
  21

Just to be pedantic, I'm going to point out that "true" MVC is impossible on any web-based system. That's because one of the things an actual MVC system has to have is the ability for the controller to post updates to the View when the Model changes. HTTP is strictly a Request/Response protocol and has no ability to asynchronously notify the client (browser) if the Model is changed between requests. The best that can be done is to include those changes with the next Response. This failing can be reduced by using AJAX to poll for changes, but it's still not going to result in a 100% pure MVC. There will always be quantum discontinuities.

However, in the real world, we're happy with "close enough". Several attempts were made over the last decade or so to get as much of the benefit of MVC as possible. One of the more successful ones was the development of the JavaServer Faces framework. Although it can't do anything about HTTP's limitations, and there is a small amount of co-mingling of code between Model and Controller, JSF has indeed proven "close enough".



Customer surveys are for companies who didn't pay proper attention to begin with.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

I'm surprised that your professor jumped straight to MVC before having the class write some simple hello world apps to get people familiar with the file structure of a Java web application. You might want to look around for some web tutorials or books on servlet programming to make sure you get all the fundamentals down before moving on to things like this.

We have some tutorials in our Cattle Drive. There is a servlet section there and it covers MVC.

We also have some example applications in our CodeBarn. The servlet applications are packaged as war files so they can be download and dropped into your tomcat/webapps directory. Once in there Tomcat will automatically unpack them and deploy them. There is an MVC app there as well.
If you download and deploy that, you'll have a running copy of an MVC app (with code) that you can use to compare with the one from the link you posted.

See: http://faq.javaranch.com/java/CodeBarnServlets


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ritesh Pareek
Ranch Hand

Joined: Nov 04, 2008
Posts: 50
@Tim Holloway

Good comment. Thanks
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
That's because one of the things an actual MVC system has to have is the ability for the controller to post updates to the View when the Model changes.


This ability is an implementation detail for a specific type of MVC implementation. The MVC OO design pattern itself does not prescribe any such requirement.

MVC-based applications which are implemented with a HTTP-based View are also "true" MVC implementations. They are just a different type of implementation than the one you describe.

A particular object-oriented design pattern can have multiple implementation styles.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16055
    
  21

Henry Pinkerton wrote:
That's because one of the things an actual MVC system has to have is the ability for the controller to post updates to the View when the Model changes.


This ability is an implementation detail for a specific type of MVC implementation. The MVC OO design pattern itself does not prescribe any such requirement.

MVC-based applications which are implemented with a HTTP-based View are also "true" MVC implementations. They are just a different type of implementation than the one you describe.

A particular object-oriented design pattern can have multiple implementation styles.


I'm showing my age. I can remember when it was still acceptable to call it Model/View/Editor. Microsoft describes 2 variants of MVC, active and passive. http://msdn.microsoft.com/en-us/library/ms978748.aspx

Active MVC relies on a 2-way asynchonous message flow. Passive MVC relies on the Observer Pattern, which, as they mentioned, is the best you can do using HTTP as a transport mechanism.

MVC was not considered as a formal "Design Pattern" in the seminal GoF book, but rather as an assembly of alternative Design Patterns. They declined to define a term for such assemblies, however. Missed opportunity.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

It would be cool to stop hijacking the thread and to know if Gabriele has solved his/her problem
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem deploying MVC with Tomcat