Transcript
Page 1: 4η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού

Container and Roadmap

Page 3: 4η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού

The apache file system

Page 4: 4η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού

CGI (non-Java) approach

Perl, C, Python, PHP, …

Page 5: 4η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού

Servlet: prepare• Build a directory tree

• Write the two files

Page 6: 4η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού

Servlet: deploy (3) and use

• Compile

• Transfer to Tomcat’s file system

• Start Tomcat

• Click path in your browser

Page 7: 4η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού

JSP

Apps developer

Web page designer

Page 8: 4η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού

Tomcat?

A container

Page 9: 4η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού

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

Page 10: 4η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού

What is a container?

Page 11: 4η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού

Containers

Page 12: 4η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού

Tomcat?

• extents Apache

• container for servlets • simple standalone server for Web applications that use

HTML, servlets, and JSP

Page 13: 4η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού

Alternative to Tomcat

• JBoss • Open source • Opinions vary on how easy it is to install • Comes with built-in database

Page 14: 4η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού

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.

Page 15: 4η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού

What a Container offers?

Helps you to concentrate on your business logic than programming details

Communication Lifecycle Management Multithreading Support Declarative Security JSP Support

Page 16: 4η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού

How the Container handles

requests?

Page 17: 4η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού

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>”);''

'''''''''}'

}'

Page 18: 4η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού

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

Page 19: 4η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού

Three different names for a servlet

Page 20: 4η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού

Why?

Flexibility

Security

Page 21: 4η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού

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>

Page 22: 4η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού

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.

Page 23: 4η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού

Scenario: An e-Matchmaker

Page 24: 4η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού

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”); } }

Page 25: 4η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού

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 } }

Page 26: 4η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού

Separate view from business logic

Page 27: 4η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού

Model View Controller

Page 28: 4η διάλεξη Τεχνολογίες Παγκόσμιου Ιστού

Model View Controller (MVC) leads to

Duplication!


Recommended