kiril
Uploaded by
6 SLIDES
211 VUES
60LIKES

Java and the Web

DESCRIPTION

This document explores the standard model of web clients and servers, focusing on the basic request/response model where a client requests a static resource and the server responds accordingly. It dives into generating dynamic content using parameters in requests, highlighting how web servers now access databases or services for user-specific content. Additionally, it provides an overview of servlet anatomy including the role of `web.xml` and an example implementation of a simple servlet (TestServlet) that generates HTML responses dynamically.

1 / 6

Télécharger la présentation

Java and the Web

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript

Playing audio...

  1. Java and the Web CSE 3330 Southern Methodist University

  2. Standard Model of the Web Client Web server Internet • Basic Request/Response Model • Client makes a request for a static resource • Web server responds with the static resource • HTTP is the standard protocol

  3. Generating Dynamic Content • Request can contain “parameters” / “key-value” pairs of information • Web server can use this data to generate dynamic content (Response) • Web server isn’t just serving up static content anymore • may be taking request params and accessing a database or other service to generate content for the user.

  4. Anatomy of a Servlet • <TCHome>/webapps • TestServlet • WEB-INF • web.xml • classes • TestServlet.java • TestServlet.class

  5. TestServlet.java public class TestServlet extends HttpServlet { public void doGet(HttpServletRequestreq, HttpServletResponse res) throws IOException, ServletException { res.setContentType("text/html"); PrintWriterout = res.getWriter(); /* Display some response to the user */ out.println("<html>"); out.println("<head>"); out.println("<title>TestServlet</title>"); out.println("</head>"); out.println("<body>"); //replace YourName below with your real name. out.println("<p>Hello There, YourName</p>"); out.println("</body></html>"); out.close(); } }

  6. web.xml <?xml version="1.0"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <servlet> <servlet-name>TestServlet</servlet-name> <servlet-class>TestServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>TestServlet</servlet-name> <url-pattern>/TestServlet</url-pattern> </servlet-mapping> </web-app>

More Related