Professional Documents
Culture Documents
Servlet: Java class loaded into Web server JSP page: enhanced HTML page that is compiled into a servlet for deployment JavaBean: data holding class (part of Model in MVC)
J2EE Architecture
Applets and special clients: downloaded, connect back to server Enterprise Java Beans: long-term, applicationscope data storage and business logic
Web.xml prolog
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" http://java.sun.com/dtd/web- app_2_3.dtd> You can validate your web.xml using the W3C validator service (recommended1) When you change your web.xml, you must ask Chris or me to reload your web-app
Servlet element
<servlet>
<servlet-name>GonzoServlet</servlet-name> <servlet-class>cs4300.Gonzo</servlet-class>
</servlet>
Or
<servlet>
<servlet-name>GonzoServlet</servlet-name> <jsp-page>gonzo.jsp</jsp-page>
</servlet>
Servlet-mapping element
<servlet-mapping>
<servlet-name>GonzoServlet</servlet-name> <url-pattern>/gonzo</url-pattern>
Welcome page
<welcome-file-list> <welcome-file> index.jsp </welcome-file> </welcome-file-list> Index.jsp is the file served at the URL http://ganesha.cs.uga.edu/myapp
<Static HTML code> Declarations Java expressions Scriptlets (chunks of Java code) Try to minimize the mixing of HTML with Java (violates Model 2 architecture)
JavaBean
Helper class that holds information Separates Java code from HTML Implements Model component of MVC architecture Useful for holding session data
JavaBean Example
Store functionality: user enters name -email pair for storage in bean Fetch functionality: user enters name, bean replies with email
JSP-Bean communication
Make <INPUT> element names in JSP correspond to variable names in Bean Write Bean class with setX() and getX() setter and getter methods <jsp:setProperty> sends inputs to Bean <jsp:getProperty> gets values from Bean
Acknowledgements
J2EE architecture diagrams: Sun J2EE tutorial, http://java.sun.com/j2ee/1.4/docs/tutorial/doc/index.html Object scopes: jGuru Java Server Pages fundamentals,
http://java.sun.com/developer/onlineTraining/JSPIntro/contents.html#JSPIntro6_3