
Java development is not limited to just desktop-based applications or website applets. Oracle, the company that maintains the Java language, also produces a product called JavaServer Pages that allows programmers to use Java for server-side Web development. This software uses files with the ".jsp" extension and can incorporate source code from standard ".java" source code files.
Server-Side Code Execution
- When a user views a website, its source code can be processed on either the server that hosts the website or on the website visitor's machine. Servers send raw HTML code for the user's machine to render a website. More complex source code is processed on the server itself and is sent to the client's machine for incorporation into the source code it's processing.
.jsp Files
- Files with a ".jsp" extension contain HTML code interspersed with Java code called directives. These segments of Java code are separated from their surrounding HTML code with the symbols "<%" (without quotes) marking the beginning of the Java code and the "%>" symbol marking the end of the Java code. The HTML code around the Java segments are sent in their raw form to the client machine for processing, while the Java code segments are executed on the website's server itself.
.java Files
- Normal Java source code files use the ".java" extension. These are uncompiled files that neither the JVM on the server or the client's computer can directly execute. The Java code in ".jsp" files can, however, import code from any ".java" files stored on the same server. This will cause the JavaServer Pages software to read in this code as well as the Java code on the ".jsp" page itself when compiling the source code into bytecode for the end user's machine to execute.
Purpose
- There are a number of reasons why a developer would have his ".jsp" file import Java code from a ".java" file instead of simply writing in the code directly. One is the normal Java coding convention of storing the source code for class files independently of one another and then calling the entire class file's code with a single declaration. Another is reducing the amount of code on the ".jsp" page so its core function is easier for developers to maintain.