tags:

views:

107

answers:

5

I've read lot of articles saying, that Java EE is most popular enterprise solution nowadays. Let's not argue if it is most popular or second most popular or what.

The thing is : I see almost all web pages with extension like .html, .php and .aspx. Why there is (almost) none .JSP ? Why so ease to find ASP.NET pages if it is supposed to be less popular?

Please I am not programming with Java EE (yet) so don't blame me, if I am completely wrong. The answer with patience would be greatly appreciated!

A: 

JSP has disadvantages, especially with JSF. With the latest version of JEE it is recommended to use facelets with JSF instead of JSP (and a frequent suffix for this is .jsf). Another frequent framework is Struts which use .do as suffix.

Thorbjørn Ravn Andersen
what about Spring. Does it have some suffix?
UnCon
@UnCon you can have jsp files as views when using Spring mvc, but you can map url requests with the path and suffix you want, most people use .htm when working with it, so if you see a "something.htm" url, does not mean you have a file with that same name.
marcos
@UnCon: While Spring offers support for MVC, it doesn't explicitly define what the used View technology is. Therefore it may be `.do`, `.html`, `.jsp`, `.jsf`, `.form` or something completely different or none at all since especially with Spring 3 you can hide your entire site behind RESTful URL:s which hide the actual underlying technology entirely.
Esko
Cool thanx!And if I download source code od page, is it possible to know which technology was used to build it? (sorry if it is idiotic)
UnCon
Usually not. Experienced developers may be able to recognize the generated HTML with Javascript as characteristic of a given framework. It is very similar to recognizing which compiler generated a given EXE-file
Thorbjørn Ravn Andersen
Even with JSF, I would hide suffixes for the same reasons JSP pages are (should be) hidden under WEB-INF. URLs should have no suffixes indicating their technologies (specially if multiple technology artifacts are weaved together to create a HTML body for a given URL request.)
luis.espinal
I am still little bit unclear what's the difference of using JSF+facelets vs JSP, but I guess that would require some investigation ...
UnCon
JSP carries a lot of baggage with it due to the JSP-compiler not being under JSF control. Facelets were invented to solve that.
Thorbjørn Ravn Andersen
+3  A: 

Most enterprise solutions would be intranets or extranets and would not be exposed to the public, so you would not know about them.

All this tells you is that you have not seen relatively many public websites written with jsp.

Oded
Do you think that quote "Java EE is more used than .NET in web solutions" is true?
UnCon
Do a search for the total number of EE jobs vs the total number of .NET jobs, and you'll find that it really seems to be the case. Having said that, it is not that much of a great margin, 5 to 4 or 3 to 2 if we eyeball the number of jobs per technology.
luis.espinal
@UnCon - No idea. As there is no way to find out all "web solutions" out there, there is no way to compare numbers.
Oded
Appreciate your effort, guys
UnCon
+1  A: 

Where JSP pages are used directly, they are often mapped to URLs in a deployment descriptor, hiding that implementation detail of the web application - so you might not be able to tell that it was a JEE-based web application.

(As requested) For example, I might write a JSP page and save in my web application as /mypage.jsp. I could then define a mapping from the (arbitrary) URL /action.do to that JSP page in my deployment descriptor (web.xml) as follows:

<servlet>
  <servlet-name>mypage</servlet-name>
  <jsp-page>/mypage.jsp</jsp-page>
</servlet>

<servlet-mapping>
  <servlet-name>mypage</servlet-name>
  <url-pattern>/action.do</url-pattern>
</servlet-mapping>

In addition, developers writing Java-based web applications use a Model-View-Controller design in which requests are routed to Controller servlets that do the heavy lifting (validating request parameters, interacting with other code and services) before dispatching to a JSP to create the response (view) the user will receive. Thus, the incoming request is mapped to the servlet, not the JSP directly. The official Sun Certified Web Component Developer qualification promotes this approach, and web frameworks like Struts and JSF are built on this approach.

Brabster
Thus, the incoming request is mapped to the servletPlease can you explain little more? (I know, I can google but it is always better from the 1st hand)
UnCon
I see thanx for edit. It is quite amazing, so now I more wonder why .asp developers don't "hide" this suffix :)
UnCon
+5  A: 

The most common answer to why you don't see .jsp extensions in URLs is because (at least with well-developed JEE sites) is that JSP pages are never accessed directly. They form templates or extension points associated to URIs and resolved by some form of controller or filter.

It used to be the case in the early years (pre-serlvlet era) that you would publish JSP-suffixed URLs, but no more.

The standard JEE practice now is to

  1. have all JSP files under WEB-INF (thus rendering them un-referenciable with URLs),
  2. define one or more controllers that handles URL requests
  3. define a mapping of each URL to a set of resources (JSP pages for instance)

The controller(s) then know how gather all those resources, compose them together and spit out the HTTP response for a HTTP request.

The reason to do so is to separate the URL from the actual artifacts used to make up the resource. If a user bookmarks your JSP page, you cannot move it or rename it, not unless you break his bookmark or introduce a HTTP redirection. But if you hide your JSPs, you can manage them anytime you want without breaking the URL.

It is pretty much an application of the rules of composition and encapsulation to URLs.

For example, imagine that you have a URL, /hello.

Then you have a header.jsp, a footer.jsp and a body.jsp file under WEB-INF (hidden from the public).

When you send a HTTP request for /hello, the controller behind it will do its magic, composing a HTML page using the header, footer and body jsp pages.

If you later need to add a navigation bar on the left (say navbar.jsp under WEB-INF), you configure your controller to compose a new HTML body using navbar.jsp to create the navigation bar.

You URL remains the same even though you added a new JSP file to its composition.

Another reason for doing so is information hiding and security. There is no reason to advertise to the outside world (or even users inside a corp's intranet) about the technology behind your web application. If you let URLs have JSP suffixes, you are telling the world that JEE is behind the scenes. Even if such knowledge poses no risk, you never want to do that.

Lastly, what happens if you ever want to change technologies, but don't want to break existing URLs? You may have a contractual obligation to keep them alive. Divorcing URLs from technology-specific file extensions will help to do that.

Hope it helps.

luis.espinal
Great answer, Thank you very much.Marked as "Answered"
UnCon
A: 

Java web development good practice generally means not exposing JSP pages directly, but rather using them as a view layer underlying the MVC pattern, in an arrangement in which they are only accessed from the controller.

The resulting URLs are therefore pretty generic, giving little clue as to what lies beneath.

skaffman