20-Nov-18 servletsJSP.ppt"> 20-Nov-18 servletsJSP.ppt">
Download presentation
Presentation is loading. Please wait.
1
Servlets and JSP 20-Nov-18 servletsJSP.ppt
2
typical web page – source
<html> <head> <title>Hello</title> </head> <body> Hello World </body> </html> <meta http-equiv=Content-Type content="text/html”> 20-Nov-18 servletsJSP.ppt
3
code <html> <head>
public class Hello extends HttpServlet { public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head>"); out.println("<title>"); out.println("Hello"); out.println("</title>"); out.println("</head>"); out.println("<body>"); out.println("</body>"); out.println("</html>"); } /* end doPost */ public void doGet(HttpServletRequest request, HttpServletResponse response) doPost(request,response); } /* end doGet */ } // end class <html> <head> <meta http-equiv=Content-Type content="text/html”> <title>Hello</title> </head> <body> Hello </body> </html> import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; 20-Nov-18 servletsJSP.ppt
4
Java Server Page <html> <head>
<meta http-equiv="Content-Type" content="text/html”> <title>Hello</title> </head> <body> Hello, today is <%= new java.util.Date() %> </body> </html> Hello, today is Mon Apr 09 19:26:58 EDT 2007 20-Nov-18 servletsJSP.ppt
5
code Hello, today is Mon Apr 09 19:26:58 EDT 2007 <html>
public class Hello extends HttpServlet { public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html>"); out.println("<head>"); out.println("<title>"); out.println("Hello"); out.println("</title>"); out.println("</head>"); out.println("<body>"); Date d = new java.util.Date(); out.println("Hello, today is “ + d); out.println("</body>"); out.println("</html>"); } /* end doPost */ public void doGet(HttpServletRequest request, HttpServletResponse response) doPost(request,response); } /* end doGet */ } // end class <html> <head> <meta http-equiv=Content-Type content="text/html”> <title>Hello</title> </head> <body> Hello, today is <%= new java.util.Date() %> </body> </html> import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; Hello, today is Mon Apr 09 19:26:58 EDT 2007 20-Nov-18 servletsJSP.ppt
6
Java Server Pages (JSP) are servlets
they have to be compiled when invoked, they run as a servlet, where the code to print out each line of HTML is generated for you 20-Nov-18 servletsJSP.ppt
7
invoking your servlet from within a JSP
you can use <jsp: > tags within the Java Server Page: <jsp:include page="/servlet/MyServlet" flush="true" /> the page buffer that the JSP has created so far is output to the browser the servlet executes and sends its output to the browser when the servlet has finished executing, control is transferred back to the JSP page and the page continues executing (sending more output to the browser) <jsp:forward page="/servlet/MyServlet" /> the JSP stops executing the servlet executes and sends its string output to the browser 20-Nov-18 servletsJSP.ppt
8
the end of this PowerPoint file
Hooray! 20-Nov-18 servletsJSP.ppt
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.