aspose file tools*
The moose likes JSP and the fly likes New Article: Scriptless JSP Pages: The Front Man Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "New Article: Scriptless JSP Pages: The Front Man" Watch "New Article: Scriptless JSP Pages: The Front Man" New topic
Author

New Article: Scriptless JSP Pages: The Front Man

Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

A rootin', tootin' new article entitled "Scriptless JSP Pages: The Front Man", written by the inimitable Bear Bibeault, appears in the latest issue of the JavaRanch Journal. You kin check out that there article here. Y'all have anything to say about it? Say it right in this thread!


[Jess in Action][AskingGoodQuestions]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12823
    
    5
Dazzling Clarity! Everybody doing JSP should read it twice and bookmark it.
Congratulations Bear
Bill
Mani Ram
Ranch Hand

Joined: Mar 11, 2002
Posts: 1140
My take of the Pop Quiz
Houston, We Have a Problem - Apollo 13
Use the Bean, Luke - Star Wars
I've Got a Bad Feeling About This - Star Wars II
Control, Control, You Must Learn Control - Star Wars ?

Couldn't identify all of them


Mani
Quaerendo Invenietis
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61652
    
  67

Originally posted by William Brogden:
Dazzling Clarity! Everybody doing JSP should read it twice and bookmark it.
Congratulations Bear
Bill


Thanks William! I consider that high praise indeed!

Originally posted by Mani Ram:

Couldn't identify all of them


Some of the are pretty obscure. I'll publish the sources later this week.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Kudos Bear.
Once again, an excellent article.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Bruno Boehr
Greenhorn

Joined: Feb 15, 2006
Posts: 17
Great article, Bear!

I liked the style, but more importantly, I liked the clear flow of logic that in a span of a handful of paragraphs presented a comprehensive overview of the evolution of the JSP engineering thought. With so many web frameworks out there it can be difficult to get a feel as to what is going on in this scene, and I think the article does a very good job at explaining the motivation for a web framework and the rationale behind some of the commonly used patterns, such as Front Servlet, PRG, Command (well, you call it controller unit) and others.

What I wish I found in the article, though, is a mention that JSP is not the only rendering technology available, and arguably not even the best one. It's a shame that Sun continually uses its power to delude developers (through careful wording of the specs, etc.) into believing that JSP is the only way to go as far as rendering is concerned.

Otherwise, I think you've just done a great favor to JavaRanch readers and the Java web development community in general. I am going to link to your article in places I hang out at

Thanks for the great work!

Bruno


<a href="http://webjavenue.com/" target="_blank" rel="nofollow">Your first website in Java: easier than you think</a>
graham king
Ranch Hand

Joined: Dec 30, 2004
Posts: 133
Hi Bear,

Thanks for the article. It's come at a good time as I have been in the past few days attempting to write my own FrontController and have found it to be rather painful.

After reading your article and some of the PRG article I've come to find that I've misunderstood the value of redirection and have used the RequestDispatcher.forward method way too much. So a good separation of controllers is needed, being the Task Controller and Page Controller.

Further in the reading you show the Front Controller delegating tasks to Task Units which themselves are not servlets. Then does this mean that the separation of controllers doesnot exist anymore? Has the Front Controller become both the Task and Page Controller? Or do the tasks themselves perform the responsibilty of updating and redirecting the requests?

Thanks again!


write, revise, re-write, revise, again...<br />write, revise, re-write, revise, again...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61652
    
  67

Originally posted by graham king:
Then does this mean that the separation of controllers does not exist anymore? Has the Front Controller become both the Task and Page Controller?


The Front Controller is semantic-less. Under a Front Controller environment, it is the Tasks that become either "operation tasks" or "page prep tasks". I didn't draw the Front Controller diagram with the PRG request flow in the interest of focusing on the Front Controller. But the PRG "pattern" (is it really wide-spread enough to deserve to be called a Pattern? see Paul Wheaton's article on patterns) is just as applicable when a Front Controller is used.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61652
    
  67

Originally posted by graham king:
Or do the tasks themselves perform the responsibilty of updating and redirecting the requests?


Unspecified/Either.

In some Front Controllers (Struts, my own 3 Chiles Atlas, and so on), the Tasks/Actions (whatever you want to call them) return information that instructs the FC itself on how to dispatch the request.

In a new Front Controller implementation that I'm working on, that responsibility is delegated to the Tasks themselves (via a delegate class that abstracts the process).
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61652
    
  67

Originally posted by Bruno Boehr:
... the rationale behind some of the commonly used patterns, such as ... Command (well, you call it controller unit) ...


Hmmm, good point. I tend to rely very heavily on Martin Fowler's Patterns of Enterprise Application Architecture and Command isn't one of the listed patterns. So I made up "Task" and the generic "unit of control".

One of the great things about patterns is that they give us a common vocabulary in which to discuss the "patterned" concepts. The downside is that not every "dictionary" agrees on what the vocabulary means -- for example, the Data Transfer Object vs. Value Object debate.

But on doing a little digging, it does appear that this is an instance of the what is accepted as the Command Pattern. David Geary, in this article states that that Struts Actions are an example of the Command pattern.

I may need to ponder the terminology choices...


What I wish I found in the article, though, is a mention that JSP is not the only rendering technology available


Well, the article's point is to identify a good pattern for web appliction structure for scriptless JSP pages. But, yes, it is true that other templating technologies exist. Though I would argue that with the advent of JSP 2.0 and scriptless pages, that JSP jumps leaps and bounds ahead of JSP 1.2 as a templating technology.


Otherwise, I think you've just done a great favor to JavaRanch readers and the Java web development community in general. I am going to link to your article in places I hang out at


Thanks! I appreciate the feedback.
[ March 22, 2006: Message edited by: Bear Bibeault ]
graham king
Ranch Hand

Joined: Dec 30, 2004
Posts: 133
Bear,

You got me pegged on the struts MVC. I've been using it for the past year and in my meager attempt to implement the Front Controller on my own, I found that without a framework, you sure do have your hands full.

Basically, I don't want to recreate the architecture on my own, but, would like to use another web application framework. Have you ever used the WAF that sun sends out with its petstore app? It looks pretty complicated and doesn't seem to have alotta documentation hanging around.
~

Thanks again for the insight!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61652
    
  67

Are you a patient man? I'm working on an implementation of a Front Controller that adheres to my "less is more" philosophy. It's highly likely that my next Journal article (in May if we keep the 2-month schedule going) will be on its design and implementation.
graham king
Ranch Hand

Joined: Dec 30, 2004
Posts: 133


By all means. Look forward to checking it out.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Bear has put a little spit and polish to the article based on the conversation here, and I've posted the new version; go check out the revised article!
Kevin Crocker
Greenhorn

Joined: Sep 06, 2002
Posts: 20
Bear,

I'm just now finding my way back to JavaRanch. Great article! Great timing (for me anyway). I'm looking forward to a better Front Controller so if you're doing one, I'm all ears.

Kevin

P.S. I sent you private email before I figured out how to get back into JR. I'll try to find a place to post here.
Gavin Tranter
Ranch Hand

Joined: Jan 01, 2007
Posts: 333
Originally posted by Mani Ram:
My take of the Pop Quiz
Houston, We Have a Problem - Apollo 13
Use the Bean, Luke - Star Wars
I've Got a Bad Feeling About This - Star Wars II
Control, Control, You Must Learn Control - Star Wars ?

Couldn't identify all of them


Surely, The Empire strikes back for the last two ?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61652
    
  67

Of course!

Btw, an implementation of Front Man is freely available. See the link in my sig.
[ August 21, 2007: Message edited by: Bear Bibeault ]
Kamal Nazar
Greenhorn

Joined: Aug 21, 2007
Posts: 1
I'm a bit confused over an aspect of this article ....


I've been implementing a FrontController - following the Core J2EE pattern - but .....

- the "Houston, We Have a Problem" section describes a scenario where the contolling servlet forwards to the JSP page to diplay the cart -
in this case - the request and any associated objects used within that scope are still available to the forwarded resource (the cart display page - in this case).

However - with the sendRedirect - the request object goes out of scope - but what if the user clicks refresh before the sendRedirect is recieved on the client - the controller still has to have logic to deal with duplicate requests - so how does having a separate page controller & the use of sendRedirect help in this case (I can see how it's of use once the client has recieved the sendRedirect response - but not how multiple refreshes before this time are handled any differently (aside from their affect being isolated to the TaskController only).


Thanks for taking the time to read this.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61652
    
  67

the controller still has to have logic to deal with duplicate requests


Of course. Not only for this reason, but for security reasons your server code can never trust what comes from the client. The Post-Redirect-Get pattern helps to make sure that your web app runs smoothly and gives the customer a good experience, but it's not meant to allow your code to get sloppy.
Baseet Ahmed
Ranch Hand

Joined: Dec 18, 2006
Posts: 224
Nice article.





Thank you.
Information Technologist


***********************************
Tip: Sincerity is mother of all acheivements.
***********************************
greg buela
Ranch Hand

Joined: Sep 04, 2007
Posts: 71
You mentioned the "less is more" principle, and I think it would be a good idea to get rid of the internal command mapping. I have read about Ruby on Rails relying on that approach, "convention over configuration", to make things simpler, and I really like that. This is possible here, we could have a convention that says that all of our application's command classes should sit in one specific package. It would be then safe to hard code the package path in the front controller, or better, to configure just the package path somewhere in web.xml so that the controller is exactly the same across applications. Then, the actual class name would be inferred from the path info (after /command/, or before *.do). I absolutely love this.
My first exposure to java web development, and java in general, was to work on an application that was already developed using the pattern you describe in the article. I was lucky.


SCJP 1.5
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61652
    
  67

Are you psychic? What you describe is very much what is planned for the next revision.

I'm not planning on getting rid of the ability to individually map commands if desired, but am planning to add a simpler "command by coonvention" ability similar to what you describe. I think I can do so without making it confusing.

Thanks for the backing that this would be a good direction to take.
greg buela
Ranch Hand

Joined: Sep 04, 2007
Posts: 71
Well, I'd have bet that was your idea, it seemed like the natural next step. And I agree to keeping the possibility of configuring the commands.
See ya!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61652
    
  67

Now I just need to find the time to do it!
Per Lindberg
Ranch Hand

Joined: Jan 17, 2008
Posts: 48
Kamal Nazar touches on a problem that has not yet been discussed much.

The canonical method for the front controller to store result data objects is to keep them in request attribute(s).

But what if we use the PRG (Post-Redirect-Get) pattern/technique.
Then we can't store the result object(s) in a request attribute,
since the request is gone when the browser sends its GET to the View.

What would be the a canonical way to keep results during a PRG operation?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61652
    
  67

The whole purpose of PRG is to completely break that dependence. The purpose of a Page Controller is to prep the page for display -- it should not depend on anything being passed to it from the Task Controller as the Page Controller is intended to be used as the first stage in displaying the page, even if that page is shown after some previous task.

Therefore the Page Controller needs to be able to act independently and fetch any data it needs from the Model and not depend on anything stored as a request scoped variable.

This could mean going back to the DB for the data, but most Models I've worked on implement smart caching so that fetching something that was just updated is a quick operation.
Frank Kellinghusen
Greenhorn

Joined: Jul 10, 2009
Posts: 11
I have a question abouth the PRG pattern. In an example PizzaOrder application I would use a POST request to order and redirect to a OrderView to view the order made. What I don't understand how to add request parameters to the GET request for the OrderView. The OrderView will need to have some kind of ID as a request parameter, so it knows which order to show. Where does the Browser get this ID from to send the appropriate GET request?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61652
    
  67

Simply add it as a request parameter to the redirect URL.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: New Article: Scriptless JSP Pages: The Front Man