Java Servlets are very like Java Applets. In fact Java Servlets can be embedded into web pages in much the same manner as Java Applets can be. Java Servlets run on a server and Java Applets run on a client machine. Therefore Java Servlets should execute faster than Java Applets since Applets are downloaded to a client machine prior to execution on the client and Servlets are executed on the server. Servlets are commonly used to generate web pages from scratch or to generate sub-sections of web pages. These web pages typically include HTML, DHTML and JavaScript. Java Servlets allow for a complete web site to be executed from the server.
Below is a simple example of a Java Servlet.
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class hithere extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<HTML>");
out.println("<BODY>");
out.println("<HEAD>");
out.println("<TITLE>Hi There !</TITLE>");
out.println("</HEAD>");
out.println("<BODY>");
out.println("<H1><font color=\"red\" size=\"6\">Hi There !</font></H1>");
out.println("</BODY>");
out.println("</HTML>");
}
}
JSP (Java Server Pages) is the Java equivalent of ASP (Active Server Pages). JSP allows the inclusion of Java coded commands into a JSP page as ASP allows the inclusion of VBScript commands into an ASP page.
There are a number of possible advantages of JSP over ASP.
JSP and Java Servlets may be faster than ASP.
JSP allows the inclusion of Java coded commands into a web page plus the use of Java Beans. Java Beans are compiled Java components. This implies that the Java Servlets plus JSP combination give the full power of a programming language, and a fully object-oriented one at that, in the creation of web pages. ASP uses VBScript which is at its best a simplistic scripting language. VBScript is a very small subset of Visual Basic. Also Visual Basic is not an object-oriented programming language.
Java is platform and browser independant. VBScript is not. In fact VBScript will generally not function very well with Netscape or any other browser other than the Internet Explorer, for instance, America On-Line. Also since Java is platform independant JSP pages can be run on any machine regardless of operating system without recompilation.
The only advantage with ASP is that VBScript is far easier to code. However, in my experience, if something is easier to code its longevity and ease of maintenenance is very likely to be awkward if not impossible after a very short period of time.