*
The moose likes Servlets and the fly likes Your opinion on my newbie Webapp Architecture Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Your opinion on my newbie Webapp Architecture" Watch "Your opinion on my newbie Webapp Architecture" New topic
Author

Your opinion on my newbie Webapp Architecture

Robert Krieg
Greenhorn

Joined: Aug 27, 2008
Posts: 9
Hello guys!

Due to the fact that i'm new here, i first want to say hellooo to all you guys!

I hope you can give me some constructive critisism on my first try of designing a solid architecture for my webapplication.

This "webapplication" is a well...simple Website, but with some dynamic content I want to update CMS-like. That's why i'm building it with JSP&Servlets technology (which I learned trough your very nice Book "HeadFirst Servlets & JSP" )

I tried to display my application design in a model, I hope you can understand it.

Here it is
--> Have a look at my model <--

Explanation:
I think on the first look, this is just common MVC (I hope so ). But i am not sure in all details, because I am very new to this. So here I just demonstrate how a User request would be handled, and it goes like this:

1. A User does send a normal GET-Request by clicking on a Men´┐Ż-Link on a jsp page.... the link URL is for example "webdesign/design.html"

2. A Filter does change that url to a more useful one like:
"ViewDispatcher?view=design..."

3. My main controller (The ViewDispatcher Servlet) does recieve this request.

4. With the parameter "view" it does lookup the path of the real *.jsp File in a Map. This Map contains View-Objects. This View-Objects have a attribute with the jsp-File-Path and some other useful Attributes i need. I think I gonna load this View-Map once out of the DB and then save it as a ContextAttribute thingy.

5. Now im not sure anymore which way is correct....

Possibilty A) The Controller get all the Data from the model, packs it into the request (request.setAttribute(...)) and passes the model to the view. For that, the servlet has to recognize, which kind of model-data the view needs. (maybee a lot of if-else)

Possibility B) The Controller directly forwards to the view (by RequestDispatcher). And then the view does retrieve all the data directly from the model.

Is it model 2-like to get the data directly from the "model-classes" and not trough the controller? I think it would be easier.

6. Response to the client...and the jsp is displayed...


--------------------------------

I think for POST-Requests I would use seperate servlets processing the Data, so this example should just be how the user clicks trough the normal website-navigation.

I know that there are kickass-Frameworks out there which would perfectly solve my problems, but I want to 1. learn it and 2. code it all by my self, so maybee I'll use frameworks later.

I'll hope on some review and thanks in advance

Greets exo
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

I always go with (A). Keep the pages as dumb as possible.

What I don't get is the filter that rewrites the URL. Why bother? It just seems like a lot of extra goop.
[ August 27, 2008: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

P.S. You may find this article interesting.
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

Originally posted by Bear Bibeault:
I always go with (A). Keep the pages as dumb as possible.


What Bear said. Dumb pages, separate business logic from presentation. Design so you can change the presentation, because someone, usually a PHB, will demand it.

Plan for it, and you can look smart.
Robert Krieg
Greenhorn

Joined: Aug 27, 2008
Posts: 9
What I don't get is the filter that rewrites the URL. Why bother? It just seems like a lot of extra goop.


I'm not sure already, but it should work like the 'mod_rewrite' modul from apache. The reason why i want to do this is to 1. Keep the URL's tidy, short and readable for the user and 2. Friendly for SearchEngines

For example

is better to read and understand than


Sure, with a good directory structure I won't even need to use it. But in some cases, a translation keeps the URL more tidy and SEO-friendly.

Do you think such a filter is a huge issue for performance?


Thank you for this article. This answers a lot of my questions. It looks like my model went in the right direction, but missed something.

This "Front Controller" mentioned in the article ist just equal to my "ViewDispatcher", but it doesn't dispatch to views, but to commands. And this commands are getting the model data and forwarding to the views. Am I right? Am my "View-Hashmap-Thing" is very similiar to the configuration map. So what I have to use is:

One Servlet (Front Servlet)
A lot of Commands (Page & Task Commands) which handles the different actions

Isn't that exactly how Struts does it?

I'll read it again before I flood you with more questions :roll:

Thank you a lot!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

Originally posted by Robert Krieg:
1. Keep the URL's tidy, short and readable for the user and 2. Friendly for SearchEngines
As long as the entry URL to your site is easy, the interior URLs shouldn't really be of any interest to your visitors, and a good sitemap will take care of search engines. But all that aside, this can all be accomplished with proper URL mapping rather then resorting to filtering the URLs.

Sure, with a good directory structure I won't even need to use it. But in some cases, a translation keeps the URL more tidy and SEO-friendly.
Directory structure is moot in the face of mappings.

Do you think such a filter is a huge issue for performance?
I'm less concerned with performance (performance issues get dealt with when they show themselves) than just the unnecessary goop. Goop tends to gum up the works and make things fragile and complex needlessly.

You might want to take a look at the mappings that my FrontMan FC implementation uses (link in sig). They're all neat and tidy and SEO friendly. Page controllers tend to have URLs like:

while task controllers tend to be:

No need for extra goop.

Isn't that exactly how Struts does it?
Pretty much (but I don;t hold the way Struts does things in generally high regard.)
[ August 27, 2008: Message edited by: Bear Bibeault ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

P.S. Using URLs that end in .html that map to dynamic resources is not the best of ideas. Browsers and intermediary servers (like the AOL servers) tend to treat them as static resources and may cache them completely out of your control.

I have a horror story from my last job where customers were getting served up other customer's data because of the "helpful" servers at AOL.
Robert Krieg
Greenhorn

Joined: Aug 27, 2008
Posts: 9
Okay, I'll have a closer look to your Frontman Mappings. They already seem to be a simple solution to have tidy URL's.

What if I need to put some parameters to the request? For example

A user is looking at a list of products. Now he pushes a button to see just the first 10 products.

Would the url look like that with a parameter?



Okay I could live with just this one parameter. But what if there are more?
Or would that action be another Command? The "command/viewFirstThenProducts" Thing?

How can I pass parameters to this commands? I can't directly access the execute()-Method of a command. And I don't think it's the Front Controller's Job to get the Parameters from the request and passes them to a command's execute() method. Now I confuse myself hehe

aaaah Edit: I found that CommandContext thing in your API, So that's how you give the command access to request, response etc. Right?


P.S. Using URLs that end in .html that map to dynamic resources is not the best of ideas. Browsers and intermediary servers (like the AOL servers) tend to treat them as static resources and may cache them completely out of your control.


Ay...good you mentioned that.


Thank you Bear, Greets Exo

[ August 28, 2008: Message edited by: Robert Krieg ]
[ August 28, 2008: Message edited by: Robert Krieg ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

Originally posted by Robert Krieg:
What if I need to put some parameters to the request? For example...
In examples such as that, it's customary to pass that data as a POST, rather than on the URL.

But yes, you can put parameters on any URL if you'd like.

And I don't think it's the Front Controller's Job to get the Parameters from the request and passes them to a command's execute() method.
Generally, it's not. The command implementation should have complete access to the request environment and can fetch the parameters itself.

aaaah Edit: I found that CommandContext thing in your API, So that's how you give the command access to request, response etc. Right?
Bingo.

It's not the only way to do things, but FrontMan was designed after a lot of experience working in this area, and with the help of some very experienced members of this board. So I like it.
Robert Krieg
Greenhorn

Joined: Aug 27, 2008
Posts: 9
In examples such as that, it's customary to pass that data as a POST, rather than on the URL. But yes, you can put parameters on any URL if you'd like.


I've searched on the javaranch and on google, but didn't found a useful hint how to send POST-Requests by pressing on a link. Is this even possible?

Or do I have to make a mini formular for each link, just to send a POST request? I don't think this is a good solution

Something like


-------------

Question 2 about the Front Controller Pattern

A lot of my JSP-Pages do have rather static content...for example the "about" page or something. Do I have to build a "viewBlabla"-Command for every JSP I have out there? Even if they don't need any model-data or just some contextAttributes?


Thanks a lot

greets Robert
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

Originally posted by Robert Krieg:
I've searched on the javaranch and on google, but didn't found a useful hint how to send POST-Requests by pressing on a link. Is this even possible?
Sure. You can either use Ajax, or cause a hidden form to be submitted. Or, if the request causes no change in client-side state, a GET is acceptable. Request params on the URL are not poison.

Or do I have to make a mini formular for each link, just to send a POST request? I don't think this is a good solution
Again, GETs shouldn;t be used (though sadly often are) for requests that change server-side state. If the request's purposes is to fetch data only, a GET with request params is fine, as mentioned above.

A lot of my JSP-Pages do have rather static content...for example the "about" page or something. Do I have to build a "viewBlabla"-Command for every JSP I have out there? Even if they don't need any model-data or just some contextAttributes?
Have to? No. Many may consider that a good practice. In a recent project I did for a client, I had a lot of such static pages, so I wrote a "view broker" servlet to complement the command broker. It uses the same same mapping approach as the command broker, except that it uses the path info to abstract the JSP (still hidden behind WEB-INF) to display. I mapped it to the /view/* prefix.

Want me to post it?
Robert Krieg
Greenhorn

Joined: Aug 27, 2008
Posts: 9
Thank you

I think first I make some more progress in my Servlet Book. I'll come back to you when I have more questions. Thank you

Have fun
 
wood burning stoves
 
subject: Your opinion on my newbie Webapp Architecture
 
Similar Threads
Difference between servlet and struts
Difference between MVC1 and MVC2
MVC (urgent)
Guidance in choosing a pattern
Mr.Neal, which architecture in the history in the Book?