0% found this document useful (0 votes)
33 views16 pages

JSP Servlet

The document introduces servlets and JavaServer Pages (JSP) technology. It discusses how servlets run on the server-side and are used to build dynamic web applications. It also explains how JSPs simplify creating dynamic web pages by separating the code and presentation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views16 pages

JSP Servlet

The document introduces servlets and JavaServer Pages (JSP) technology. It discusses how servlets run on the server-side and are used to build dynamic web applications. It also explains how JSPs simplify creating dynamic web pages by separating the code and presentation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Introduction to Servlet & JSP

Krerk Piromsopa.
Department of Computer Engineering.
Chulalongkorn University

Krerk Piromsopa. Servlet & JSP 1


Krerk Piromsopa. Servlet & JSP 2
Servlet Technology

• JAVA APPLETs run on client side (in web browsers) or


writing Internet applications.
• JAVA SERVLETs run on server side for web-based
application. (No GUI is required)

• JAVA have built-in support for multithread.

• Servlet API is Standard Java Extension API, (NOT part of


core Java) and available as add-on package.

Krerk Piromsopa. Servlet & JSP 3


Servlets Overview

• Protocol and Platform-


independent server side Java
components
• Clients may range from simple
HTML forms to Java applets.
• Used as middle tiers for
distributed application systems.

Krerk Piromsopa. Servlet & JSP 4


Applications & Usage Modes.

• Database Connection. • Filter chains of Servers.


• Synchronization (On-line • HTTP
conferencing) • CGI replacement
• Virtual Server management • Server side include
• etc.

Krerk Piromsopa. Servlet & JSP 5


Security.

• Rely on HTTP-specific authentication


• Secure Socket Layer (SSL)
• Java advantage: no memory access violations, strong
typing violations. (Servlet will not crash servers.)
• Security Manager. Only trusted servlets will be allow to
access network services or local files.
• Support fine grained access control (more secure than MS.
ActiveX.)

Krerk Piromsopa. Servlet & JSP 6


Performance

Servlet run as light


weight thread in
process.

CGI run as heavy


weight process.

Krerk Piromsopa. Servlet & JSP 7


Three Tier Applications.

Krerk Piromsopa. Servlet & JSP 8


Sample Servlet
Hello World!
import java.io.*; PrintWriter out = response.getWriter();
import javax.servlet.*; out.println("<html>");
import javax.servlet.http.*; out.println("<body>");
out.println("<head>");
public class HelloWorld extends out.println("<title>Hello
HttpServlet { World!</title>");
out.println("</head>");
public void doGet(HttpServletRequest out.println("<body>");
request, HttpServletResponse out.println("<h1>Hello World!</h1>");
response) out.println("</body>");
throws IOException, ServletException out.println("</html>");
{ }
response.setContentType("text/html");

Krerk Piromsopa. Servlet & JSP 9


JavaServer Pages VS. Servlets.

• Dynamic Page require for.


– Working on any web or application server
– Separating the application logic from the appearance of the page
– Allowing fast development and testing
– Simplifying the process of developing interactive web-based
applications
• JSP is a new approach to fit this need.
• Servlet ,to turn page, have to edit and recompile.

Krerk Piromsopa. Servlet & JSP 10


JavaServer Pages Approach.

• Separating content generation from presentation


• Emphasizing reusable components
• Simplifying page development with tags

• Java Technology benefits (memory management and


security.
• Scalability (integrated with J2EE)

Krerk Piromsopa. Servlet & JSP 11


JSP Example.
<HTML>
<%@ page language=="java" imports=="com.wombat.JSP.*" %>
<H1>Welcome</H1>
<P>Today is </P>
<jsp:useBean id=="clock" class=="calendar.jspCalendar" />
<UL>
<LI>Day: <%==clock.getDayOfMonth() %>
<LI>Year: <%==clock.getYear() %>
</UL>
<% if (Calendar.getInstance().get(Calendar.AM_PM) ==== Calendar.AM) { %>
Good Morning
<% } else { %>
Good Afternoon
<% } %>
<%@ include file=="copyright.html" %>
</HTML>

Krerk Piromsopa. Servlet & JSP 12


JSP components.

• JSP Directives • Scripting Elements (scriptlet)


– <%@ …. %> – <% ... %>
• JSP Tags
– <jsp:useBean … />
– <jsp:setProperty … />
– <jsp:getProperty … />
– <jsp:include … />
– <jsp:forward … />
• JSP expression
– <%== … %>

Krerk Piromsopa. Servlet & JSP 13


Application Model

• Simple Application

• Flexible Application with Java Servlets

Krerk Piromsopa. Servlet & JSP 14


Application Model (Continue)

• Scalable Processing with Enterprise JavaBeans


Technology.

Krerk Piromsopa. Servlet & JSP 15


References

• “JAVASERVER PAGES WHITE PAPER,”


http://java.sun.com/products/jsp/whitepaper.html
• “JAVA SERVLET TECHNOLOGY,”
http://java.sun.com/products/servlet/whitepaper.html

Krerk Piromsopa. Servlet & JSP 16

You might also like