Java Servlets and JSP
Java Servlets and JSP
Java Servlets and JSP
browser
web server
servlet container
(engine) - Tomcat
First java servlet
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd version="2.5">
</web-app>
Configuring servlets
for JSPs (Java Server Pages) no additional
configuration needs to be done
for java servlets additional lines must be placed in the
web.xml file:
<servlet>
<servlet-name>ServletsName</servlet-name>
<servlet-class>The_Class_Name_of_the_Servlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name> ServletsName </servlet-name>
<url-pattern>/URL_of_the_servlet</url-pattern>
</servlet-mapping>
First JSP file
<html>
<body>
<%
out.println(“First JSP… It works<br/>");
%>
</body>
</html>
What is a Java Server Page (JSP)
an html file containing parts of java code; the java code
is placed inside the “<% … %>” tags or some other
related tags
Tomcat will create a servlet from the jsp file (which will
be saved in the work folder)
when the jsp is requested the servlet is executed and
the output of the server is sent back to the client
Additional documentation
for Servlets:
http://www.cs.ubbcluj.ro/~florin/PDPJ/ExempleSurseDocumentatii/07JavaServlet.pdf
for JSP:
http://www.cs.ubbcluj.ro/~florin/PDPJ/ExempleSurseDocumentatii/08JavaServerPages.pdf
examples of both:
http://www.cs.ubbcluj.ro/~forest/wp/JSP%20Servlet%20examples