Slides
Slides
Slides
Windows NT
Internet Explorer
Borland Jbuilder
Apache with Tomcat
Mysql Database
– www.mysql.com
PHP &
phpMyAdmin
A Historical Perspective
First efforts at
dynamic Web content
– Common Gateway
Interface (CGI)
– Fast CGI
Proprietary Solutions
– Microsoft’s Active
Server Pages
– Netscape’s Javascript
CGI: What is it?
Common Gateway A standard interface
Interface (CGI) between a Web server
programs can be and an application.
written in many One of the first
languages, including practical ways for
Java. Perl is the most generating dynamic
common language for content.
CGI's, due to its
Runs as a separate
advanced text
process from the Web
processing capabilities.
server.
Interaction with CGIs
{
// declaration of instance variables
} // skeletonServlet
Servlets & HTML
Creating HTML Documents
– setContentType()
– getWriter()
Retrieving Form Data
– getParameterNames()
– getParameter()
– getParameterValues()
Invoking the Servlet
More Servlet Examples
Vacation Example
– See demonstration.
Quiz #1
– See demonstration.
Java IDE’s & Servlets
IDE
– Integrated Development
Environment
Examples
– Borland Jbuilder
– IBM Visualage
Servlet Aids
– Automatic Code
Generation
– Test Environment
Servlet-Enabled Web Servers
Apache with
Tomcat
iPlanet
IBM Websphere
Other
See http://java.sun.com/products/servlet/industry.html
for a more comprehensive list.
The Servlet Specification
Created from Newest servlet specification includes:
a Sun- – Concept of a Web Application (Servlets,
sponsored JSP, HTML, Classes, other resources) with
open process conventions for the directory structure
to develop – Web Application Archive (WAR) files
and revise – Filtering
Allows on-the-fly transformations of HTTP
JavaTM content (request or response); for example,
technology to transform XML content
specifications – Other
http://java.sun.com/aboutJava/communityprocess/first/jsr053/index.html
Servlet Basics: A Closer Look
The ServletRequest The ServletResponse
Interface Interface
– Defines an object used – Defines an object for
to encapsulate sending MIME data
information about the back to the client from
client’s request. the servlet’s service()
– Includes information method.
about parameter
name/value pairs.
HttpServletRequest Interface
A Few Methods
– getPathInfo()
– getAuthType()
– getPathTranslated()
– getCookies()
– getQueryString()
– getDateHeader() – getRemoteUser()
– getHeader() – getRequestedSessionId()
– getHeaderNames() – getRequestedURI()
– getIntHeader() – getServletPath()
– getMethod() – getSession()
HttpServletResponse Interface
Static Final Variables A Few Methods
– For example, SC_OK – addCookie()
represents a status code – encodeURL()
of 200, and – sendError()
SC_NOT_FOUND
represents a status code – sendRedirect()
of 404. – setDateHeader()
– setHeader()
– setStatus()
Servlet Tips
Place costly functions in init().
Let doGet() call doPost() or vice versa:
public void doPost(HttpServletRequest
req, HttpServletResponse res) throws
ServletException, IOException {
doGet(req, res);
}
Be careful with multiple threads;
SingleThreadModel may be necessary.
JDBC
Java Database Connectivity
Relational Databases
SQL Refresher
– CREATE
– INSERT
– UPDATE
– DELETE
– SELECT
JDBC Features
A Java API for: Easy Object to
– Opening a connection Relational Mapping
to a database Database
– Executing a SQL Independence
statement
Distributed
– Processing the results
Computing
– Closing the connection
to the database
Basic JDBC Methods
Establishing a connection with getConnection()
Creating SQL Statements
– CreateStatement()
executeQuery()
executeUpdate()
execute()
Include Comments
– Allows the substitution of text – Two forms:
or code <!-- comments …-->
Ex: <%@ include file=“copyright.html” %> <%-- comments … --%>
Declarations Expressions
– Contains Java variables and – Scriptlet fragments whose
methods called from an results can be converted to
expression block. String objects.
Syntax: <%! Declaration(s) %> <%= expression %>
HowFar as a JSP file
HowFar.jsp
– See demonstration.
JSP and JavaBeans
Supports the creation of Tags
dynamic content – jsp:useBean
JavaBeans Declares the JavaBean
object that you want to
– Reusable software
use within the JSP
components that can be
manipulated visually in a – jsp:getProperty
builder tool Inserts the String type
of the object into the
– Minimum Requirements:
output stream
Supports JDK 1.1 and later
Serialization Model – jsp:setProperty
Uses Get/Set accessors to Sets properties of the
expose its properties Bean
HowFar2 as a JSP file with a JavaBean
HowFar2.jsp
– See demonstration.
Practical Applications
Useful for serving as University of
the “glue” to connect Mississippi IT
heterogeneous Applications
information systems – E-forms
Requires data from
that require a web Cold Fusion/SQL
interface. Server and SAP via
Java Connector
XML makes this – Web-to-SAP
scenario even more Business Connector
attractive. Java Connector
Servlet Resources
See accompanying handouts.
For More Information