0% found this document useful (0 votes)
24 views

Web Technologies: Brought To You by The Univ. of Thessaly and M. Vavalis

This document provides an overview of static versus dynamic web content and introduces servlets. It discusses how static pages exist before a request while dynamic pages are generated from code in response to requests. Common Gateway Interface (CGI) is presented as a standard for generating dynamic web pages via executable files. Shortcomings of CGI include performance issues and not being designed for Java. Servlets are then introduced as a Java alternative that avoids CGI problems through being lightweight with easy threading. Code examples are given for writing and deploying a simple servlet that generates dynamic content.

Uploaded by

klaprot
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Web Technologies: Brought To You by The Univ. of Thessaly and M. Vavalis

This document provides an overview of static versus dynamic web content and introduces servlets. It discusses how static pages exist before a request while dynamic pages are generated from code in response to requests. Common Gateway Interface (CGI) is presented as a standard for generating dynamic web pages via executable files. Shortcomings of CGI include performance issues and not being designed for Java. Servlets are then introduced as a Java alternative that avoids CGI problems through being lightweight with easy threading. Code examples are given for writing and deploying a simple servlet that generates dynamic content.

Uploaded by

klaprot
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Web Technologies Lecture 4

Brought to you by the Univ. of Thessaly and M. Vavalis

Content
Technical Issues Static vs. Dynamic content Your first exposition to servlets

Technical Issues
Check chrome apps
HTTP headers CSS viewer

Dart is out

Static vs Dynamic content

Static vs. dynamic content

Dynamic pages dont exist before the request comes in. Its like making an HTML page out of air.
The request comes in, the helper app writes the HTML, and the web server gets it back to the client.

Common Gateway Interface (CGI)


a standard method for web servers software to delegate the generation of web pages to executable files. Such files are known as CGI scripts
they are programs,
often stand-alone applications, usually written in a scripting language.

example

CGI (nonJava) approach


Perl, C, Python, PHP,

Whats wrong with CGI?


Logical
Java is suppose to be the language of the internet

Performance
Light-weight Easy thread manipulation

Productivity
J2EE

Servlet: Write
import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public class Ch1Servlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {

Save it to Servlet.java

PrintWriter out = response.getWriter(); java.util.Date today = new java.util.Date(); out.println(<html> + <body> + <h1 align=center>HF\s Chapter1 Servlet</h1> + <br> + today + </body> + </html>); } }

Servlet: deploy (1)


<?xml version=1.0 encoding=ISO-8851-1 ?> <web-app xmlns=http://java.sun.com/xml/ns/j2ee xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:schemaLocation=http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd version=2.4> <servlet> <servlet-name>Servlet</servlet-name> <servlet-class>Ch1Servlet</servlet-class> Save this </servlet>

<servlet-mapping> <servlet-name>Servlet</servlet-name> <url-pattern>/Serv1</url-pattern> </servlet-mapping> </web-app>

deployment descriptor (DD) to web.xml

Servlet: deploy (2)


Save your files in your file system

Servlet: deploy (3) and use


Compile Transfer to Tomcats file system Start Tomcat Click path in your browser

You might also like