Question

I'm learning about Apache Tomcat and I didn't understand the term implementation from the below line. I was thinking Tomcat runs Java Servlet and the JavaServer Pages (JSP).

Tomcat implements the Java Servlet and the JavaServer Pages (JSP) specifications from Sun Microsystems

Does Tomcat implement or run the Java Servlet and the JavaServer Pages (JSP)?

Was it helpful?

Solution

JavaServerPages (JSR 245) and Java Servlet (JSR 315) are Java specifications.

They are just that: a set of guidelines that are joined in a document full of words about what they are, how they should behave, etc..

Now here's the answer to your question: Vendors take those specifications to make libraries or products that implement these specifications, thus becoming an implementation thereof. This much in the way you'd implement an interface.

Therefore

Tomcat implements Java Servlet and the JSP specifications

is the right way to say describe that. Now Tomcat has its own HttpServlet implementation but you needn't worry about that because your classes just extend it.

Of course, your own servlets and JSPs will run on Tomcat but they'll extend their own implementations. Similarly they'll run on, eg., Jetty where they'll be extending different implementations of the classes.

Note that those classes (HttpServlet, ...) are in packages that start with javax. and not java.. The difference is key and I suggest that you have a look at: javax vs java package

Another widely popular example is JPA: https://jcp.org/en/jsr/detail?id=338 and its many implementations like Hibernate, EclipseLink, OpenJPA, DataNucleus, etc.

OTHER TIPS

You can run Servlet in a container that is capable of runing Servlets. Such containers include

Tomcat
GlassFish
WebSphere
Jetty etc.

.

JSP - which stands for Java Server Page - is more of a web page, that can include HTML and XML and other technologies (or languages should i say). JSP is similar to PHP but uses Java language.

"Tomcat implements the Java Servlet and the JavaServer Pages (JSP) specifications from Sun Microsystems" <- this means that Tomcat can run both - in essence

"...specifications from Sun Microsystems (Or call it Oracle as Sun does not exist anymore)", What this means is that Tomcat is capable of implementing language specifications set by Sun ( Oracle now ).

The specification you are after are JSR-000315 Java Servlet and JSR-00245 Java Server Page

So it provides a "pure Java" HTTP web server environment for Java code to run in.

Note : Servlets can be generated automatically from Java Server Pages (JSP) by the JavaServer Pages compiler. The difference between servlets and JSP is that servlets typically embed HTML inside Java code, while JSPs embed Java code in HTML.

I mean there is not much more to it ...

You should give a bit more context, so that people have a chance to help you.

Apache Tomcat is a java servlet engine and thus implements among others the specification of java servlets. It means, it is a container for java applications bundled in a war file, containing servlets.

JavaEE is all about specifications basically set of interfaces & abstract classes, all these specifications are under javax package.

Implementation provider use these specification and provide implementations.

Here is an example of tomcat server, using servlet specifications. https://github.com/apache/tomcat/tree/3e5ce3108e2684bc25013d9a84a7966a6dcd6e14/java/javax

Our code is not dependent on any of the implementation of tomcat, basically bridge pattern used where, application access the implementation through the interface which will remain same.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top