• Like
4th Lecture:  JSP and such
Upcoming SlideShare
Loading in...5
×

4th Lecture: JSP and such

  • 434 views
Uploaded on

An overview of what comes.

An overview of what comes.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
434
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
12
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Web Technologies 4th Lecture: JSP and such Σάββατο, 2 Νοεμβρίου 2013
  • 2. Last Week • HTML & CSS • TCP/IP, DNS, URL, URI • HTTP and such
  • 3. URL (and many other UR*s) • Uniform Resource Locators
  • 4. Ports • A 16-bit number that identifies a particular program on the server hardware. • 0-1023 reserved • sys-admins control them
  • 5. The apache file system
  • 6. Missed last week
  • 7. Missed last week
  • 8. Static vs Dynamic content
  • 9. Static vs. dynamic content
  • 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. 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. example
  • 13. CGI (nonJava) approach Perl, C, Python, PHP, …
  • 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. Servlet: prepare • Build a directory tree • Write the two files
  • 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. 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. Servlet: deploy (2) Save your files in your file system
  • 19. Servlet: deploy (3) and use • • • • Compile Transfer to Tomcat’s file system Start Tomcat Click path in your browser
  • 20. But … • Stuff HTML as a string into java (println)? • Why not stuff Java into HTML (or XML)?
  • 21. Web page designer Apps developer Java Server Pages JSP
  • 22. What is a Container?
  • 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. How the Container handles requests?
  • 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. 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. Three different names for a servlet
  • 28. Why? • Flexibility • Security
  • 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. 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. Prepare Yourself • http://tomcat.apache.org/tomcat-7.0doc/appdev/ • Netbeans • Stackoverflow and friends