Container and Roadmap
CSSCube with rotating navigation
The Maids of Honour (Las Meninas)
The apache file system
CGI (non-Java) approach
Perl, C, Python, PHP, …
Servlet: prepare• Build a directory tree
• Write the two files
Servlet: deploy (3) and use
• Compile
• Transfer to Tomcat’s file system
• Start Tomcat
• Click path in your browser
JSP
Apps developer
Web page designer
Tomcat?
A container
web application? • is a web site that:
• “Knows who you are”--it doesn’t just give you static pages, it interacts with you
• Can permanently change data (such as in a database) • can consist of multiple pieces
• Static web pages (possibly containing forms) • Servlets • JSP
• Tomcat organizes all these parts into a single directory structure for each web application • ...but you have to help with the organization
What is a container?
Containers
Tomcat?
• extents Apache
• container for servlets • simple standalone server for Web applications that use
HTML, servlets, and JSP
Alternative to Tomcat
• JBoss • Open source • Opinions vary on how easy it is to install • Comes with built-in database
Jboss vs TomcatJBoss If:
application requires advanced J2EE features (queues, topics …) environment needs a complete solution for failover, high availability, support, etc.
Tomcat If: application requirements are covered by a web framework like Wicket, Grails, etc. environment has knowledgeable network and server admins.
JBoss uses Tomcat as it's web container. Tomcat may run the JBoss microkernel to gain J2EE features.
What a Container offers?
Helps you to concentrate on your business logic than programming details
Communication Lifecycle Management Multithreading Support Declarative Security JSP Support
How the Container handles
requests?
Back to the code (servlet.java) import'javax.servlet.*;'
import'javax.servlet.h3p.*;'
import'java.io.*;'
'
public'class'Ch1Servlet'extends'H3pServlet'{''
''''''''public'void'doGet(H3pServletRequest'request,''
'H3pServletResponse'response)''
'throws'IOExcepHon'{''
'
''''''''PrintWriter'out'='response.getWriter();''
'''''''''java.uHl.Date'today'='new'java.uHl.Date();''
''''''''out.println(“<html>'“'+''
'''''''''''''''''''''''''''''“<body>”'+''
'''''''''''''''''''''''''''''“<h1'align=center>HF\’s'Chapter1'Servlet</h1>”'+''
'''''''''''''''''''''''''''''“<br>”'+'today'+'“</body>”'+'“</html>”);''
'''''''''}'
}'
QuestionsWhere service() comes from?
How the container finds the correct servlet?
Does the URL define where exactly the servlet is?
Possible answers • The user gives precise URL • The container’s tool does the mapping • We store the mapping to the properties table
Three different names for a servlet
Why?
Flexibility
Security
Map URLs top Servlet with DD
Deployment Descriptor (DD) has 2 elements
<web-app ...>
<servlet> <servlet-name>Internal name 1</servlet-name> <servlet-class>foo.Servlet1</servlet-class> </servlet> <servlet> <servlet-name>Internal name 2</servlet-name> <servlet-class>foo.Servlet2</servlet-class> </servlet>
<servlet-mapping> <servlet-name>Internal name 1</servlet-name> <url-pattern>/Public1</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>Internal name 2</servlet-name> <url-pattern>/Public2</url-pattern> </servlet-mapping>
</web-app>
Manipulate without touching with DD
Minimizes touching source code that has already been tested. fine-tune your app’s capabilities, even if you don’t have the source code. adapt your application to different resources (like databases), without having to recompile and test any code. maintain dynamic security info like access control lists and security roles. non-programmers may modify and deploy your web applications.
Scenario: An e-Matchmaker
First try// import statements public class DatingServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
// business logic goes here, depending // on what this servlet is supposed to do // (write to the database, do the query, etc.)
PrintWriter out = response.getWriter();
// compose the dynamic HTML page out.println( “something really ugly goes here”); } }
Second try// import statements public class DatingServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
// business logic goes here, depending // on what this servlet is supposed to do // (write to the database, do the query, etc.)
// forward the request to a specific JSP page // instead of trying to print the HTML // to the output stream } }
Separate view from business logic
Model View Controller
Model View Controller (MVC) leads to
Duplication!
Top Related