Web Technologies
4th Lecture: JSP and such

Σάββατο, 2 Νοεμβρίου 2013
Last Week
• HTML & CSS
• TCP/IP, DNS, URL, URI
• HTTP and such
URL (and many other UR*s)
• Uniform Resource Locators
Ports
• A 16-bit number that
identifies a particular
program on the server
hardware.
• 0-1023 reserved
• sys-admins contro...
The apache
file system
Missed
last
week
Missed last week
Static vs Dynamic content
Static vs. dynamic content
Dynamic (deep) Web
• Dynamic pages don’t exist before the request
comes in.
• It’s like making an HTML page out of air.
– ...
Common Gateway Interface (CGI)
• a standard method for web servers software
to delegate the generation of web pages to
exe...
example
CGI (nonJava)
approach
Perl, C, Python, PHP, …
What’s wrong with CGI?
• Logical
– Java is suppose to be the language of the internet

• Performance
– Light-weight
– Easy...
Servlet: prepare
• Build a directory tree

• Write the two files
Servlet: Write
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class Ch1Servlet extends Http...
Servlet: deploy (1)
<?xml version=”1.0” encoding=”ISO-8851-1” ?>
<web-app xmlns=”http://java.sun.com/xml/ns/j2ee”
xmlns:xs...
Servlet: deploy (2)
Save your files in your file system
Servlet: deploy (3) and use
•
•
•
•

Compile
Transfer to Tomcat’s file system
Start Tomcat
Click path in your browser
But …
• Stuff HTML as a string into java (println)?
• Why not stuff Java into HTML (or XML)?
Web page
designer

Apps
developer

Java Server Pages JSP
What is a Container?
What a Container offers?
• Help you to concentrate on your business logic
than programming details
– Communication
– Lifec...
How the Container handles requests?
Back to the code (servlet.java)
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class Ch1Ser...
Questions
• Where service() comes from?
• How the container finds the correct servlet?
• Does the URL define where exactly...
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 nam...
Manipulate without touching with DD
• Minimizes touching source code that has already
been tested.
• fine-tune your app’s ...
Prepare Yourself
• http://tomcat.apache.org/tomcat-7.0doc/appdev/
• Netbeans
• Stackoverflow and friends
4th Lecture:  JSP and such
Upcoming SlideShare
Loading in …5
×

4th Lecture: JSP and such

519 views

Published on

An overview of what comes.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
519
On SlideShare
0
From Embeds
0
Number of Embeds
300
Actions
Shares
0
Downloads
14
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

4th Lecture: JSP and such

  1. 1. Web Technologies 4th Lecture: JSP and such Σάββατο, 2 Νοεμβρίου 2013
  2. 2. Last Week • HTML & CSS • TCP/IP, DNS, URL, URI • HTTP and such
  3. 3. URL (and many other UR*s) • Uniform Resource Locators
  4. 4. Ports • A 16-bit number that identifies a particular program on the server hardware. • 0-1023 reserved • sys-admins control them
  5. 5. The apache file system
  6. 6. Missed last week
  7. 7. Missed last week
  8. 8. Static vs Dynamic content
  9. 9. Static vs. dynamic content
  10. 10. Dynamic (deep) Web • Dynamic pages don’t exist before the request comes in. • It’s like making an HTML page out of air. – request comes in, – helper app “writes” the HTML, and – web server gets it back to the client.
  11. 11. Common Gateway Interface (CGI) • a standard method for web servers software to delegate the generation of web pages to executable files. • Such files are known as CGI scripts – they are programs, • often stand-alone applications, • usually written in a scripting language.
  12. 12. example
  13. 13. CGI (nonJava) approach Perl, C, Python, PHP, …
  14. 14. What’s wrong with CGI? • Logical – Java is suppose to be the language of the internet • Performance – Light-weight – Easy thread manipulation • Productivity – J2EE
  15. 15. Servlet: prepare • Build a directory tree • Write the two files
  16. 16. Servlet: Write import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public class Ch1Servlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { Save it to Servlet.java PrintWriter out = response.getWriter(); java.util.Date today = new java.util.Date(); out.println(“<html> “ + “<body>” + “<h1 align=center>HF’s Chapter1 Servlet</h1>” + “<br>” + today + “</body>” + “</html>”); } }
  17. 17. Servlet: deploy (1) <?xml version=”1.0” encoding=”ISO-8851-1” ?> <web-app xmlns=”http://java.sun.com/xml/ns/j2ee” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd” version=”2.4”> <servlet> <servlet-name>Servlet</servlet-name> <servlet-class>Ch1Servlet</servlet-class> Save this </servlet> <servlet-mapping> <servlet-name>Servlet</servlet-name> <url-pattern>/Serv1</url-pattern> </servlet-mapping> </web-app> deployment descriptor (DD) to web.xml
  18. 18. Servlet: deploy (2) Save your files in your file system
  19. 19. Servlet: deploy (3) and use • • • • Compile Transfer to Tomcat’s file system Start Tomcat Click path in your browser
  20. 20. But … • Stuff HTML as a string into java (println)? • Why not stuff Java into HTML (or XML)?
  21. 21. Web page designer Apps developer Java Server Pages JSP
  22. 22. What is a Container?
  23. 23. What a Container offers? • Help you to concentrate on your business logic than programming details – Communication – Lifecycle Management – Multithreading Support – Declarative Security – JSP Support
  24. 24. How the Container handles requests?
  25. 25. Back to the code (servlet.java) import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public class Ch1Servlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { PrintWriter out = response.getWriter(); java.util.Date today = new java.util.Date(); out.println(“<html> “ + “<body>” + “<h1 align=center>HF’s Chapter1 Servlet</h1>” + “<br>” + today + “</body>” + “</html>”); } }
  26. 26. Questions • Where 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
  27. 27. Three different names for a servlet
  28. 28. Why? • Flexibility • Security
  29. 29. 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>
  30. 30. 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.
  31. 31. Prepare Yourself • http://tomcat.apache.org/tomcat-7.0doc/appdev/ • Netbeans • Stackoverflow and friends

×