web server programming 1. nuts and bolts. premises of course provides general introduction, no...
TRANSCRIPT
![Page 1: Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some](https://reader035.vdocument.in/reader035/viewer/2022072014/56649ea75503460f94baad9c/html5/thumbnails/1.jpg)
Web Server Programming
1. Nuts and Bolts
![Page 2: Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some](https://reader035.vdocument.in/reader035/viewer/2022072014/56649ea75503460f94baad9c/html5/thumbnails/2.jpg)
Premises of Course
• Provides general introduction, no in-depth training• Assumes some HTML knowledge• Assumes some programming experience• Assumes some knowledge of object orientation• Only treats JAVA applications. Alternatives:
– Perl, (PHP)
– XML
![Page 3: Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some](https://reader035.vdocument.in/reader035/viewer/2022072014/56649ea75503460f94baad9c/html5/thumbnails/3.jpg)
Web Services
• Document level– XML + Style sheets– Client-side programming (javascript, applets)– Server-side programming:
• CGI
• JAVA servlets
• HTML++ / XML++ (SSI: php, asp, jsp)
• RPCs
![Page 4: Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some](https://reader035.vdocument.in/reader035/viewer/2022072014/56649ea75503460f94baad9c/html5/thumbnails/4.jpg)
Contents of this course
• Web technology: protocols & languages
• Web server: request handling, output generation, session & user management
• Server programming:– Java servlets– JSP
![Page 5: Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some](https://reader035.vdocument.in/reader035/viewer/2022072014/56649ea75503460f94baad9c/html5/thumbnails/5.jpg)
What This Course Is NOT About
• RPCs
• Use of XML for (enterprise) web services
• Layout & content management
• Use of external components (databases, etc.)
• Client based software (applets, etc.)
![Page 6: Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some](https://reader035.vdocument.in/reader035/viewer/2022072014/56649ea75503460f94baad9c/html5/thumbnails/6.jpg)
About the Web
• Reinier Post
![Page 7: Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some](https://reader035.vdocument.in/reader035/viewer/2022072014/56649ea75503460f94baad9c/html5/thumbnails/7.jpg)
JAVA Support
• Component based
• Platform independent
• Built-in security
• Software libraries for every application
![Page 8: Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some](https://reader035.vdocument.in/reader035/viewer/2022072014/56649ea75503460f94baad9c/html5/thumbnails/8.jpg)
Web Applications
• Cooperating parts:– (HTML) documents– Servlets– JSP pages– Applets (client side software)
• Common context– Properties (appl. param., configuration data)– Resources (shared data)
![Page 9: Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some](https://reader035.vdocument.in/reader035/viewer/2022072014/56649ea75503460f94baad9c/html5/thumbnails/9.jpg)
JAVA servlets
Alternative for CGI scripts:
• JAVA technology
• Servlet support integrated in server– JAVA threads: no independent process– Sharing of resources
• Protocol independent
• Security issues: JAVA sandbox
![Page 10: Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some](https://reader035.vdocument.in/reader035/viewer/2022072014/56649ea75503460f94baad9c/html5/thumbnails/10.jpg)
JSP Pages
• Based on HTML or XML
• Contain processing tags
• Use servlet classes
• Converted to servlet
![Page 11: Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some](https://reader035.vdocument.in/reader035/viewer/2022072014/56649ea75503460f94baad9c/html5/thumbnails/11.jpg)
What About Servlets?
• Standard for interfacing web client with web server.
• Set of JAVA packages (javax.servlet, javax.servlet.http)
• Way of interfacing clients with back-end services (JDBC servers, etc.)
• Way to implement proxies (e.g. for applets)
![Page 12: Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some](https://reader035.vdocument.in/reader035/viewer/2022072014/56649ea75503460f94baad9c/html5/thumbnails/12.jpg)
Servlet API
• Interface Servlet
• Interface ServletConfig
• Interface ServletContext
• Interface ServletRequest
• Interface ServletResponse
![Page 13: Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some](https://reader035.vdocument.in/reader035/viewer/2022072014/56649ea75503460f94baad9c/html5/thumbnails/13.jpg)
Interface Servlet
• Init()
• Service()
• Destroy()
• getServletConfig()
• getServletInfo()
![Page 14: Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some](https://reader035.vdocument.in/reader035/viewer/2022072014/56649ea75503460f94baad9c/html5/thumbnails/14.jpg)
Class HttpServlet
• Inherits from GenericServlet (impl. Servlet)• Additional methods:
– doGet()– doPost()– doHead()– doDelete()– doOptions()– doTrace()
![Page 15: Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some](https://reader035.vdocument.in/reader035/viewer/2022072014/56649ea75503460f94baad9c/html5/thumbnails/15.jpg)
Requests and Responses
• Interface HttpServletRequest– Request as stream
– HTTP headers
– Parameters
– Path info
• Interface HttpServletResponse– Output stream
– HTTP headers
– Cookies
![Page 16: Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some](https://reader035.vdocument.in/reader035/viewer/2022072014/56649ea75503460f94baad9c/html5/thumbnails/16.jpg)
Example: TestServlet.java
• Implements doGet() and doPost() using common (private) function doIt()
• Analyses client request and shows:– Servlet requested– Path info– Get and post parameters
![Page 17: Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some](https://reader035.vdocument.in/reader035/viewer/2022072014/56649ea75503460f94baad9c/html5/thumbnails/17.jpg)
public class TestServlet extends HttpServlet { private static final String CONTENT_TYPE = "text/html"; private PrintWriter out; //Initialize global variables public void init() throws ServletException { } //Process the HTTP Get request public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { doIt(request, response); } //Process the HTTP Post request public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { doIt(request, response); } private void doIt(HttpServletRequest req, HttpServletResponse res) throws
ServletException, IOException { res.setContentType(CONTENT_TYPE); out = res.getWriter(); out.println("<html>"); .. out.println("</html>"); } //Clean up resources public void destroy() { }}
![Page 18: Web Server Programming 1. Nuts and Bolts. Premises of Course Provides general introduction, no in-depth training Assumes some HTML knowledge Assumes some](https://reader035.vdocument.in/reader035/viewer/2022072014/56649ea75503460f94baad9c/html5/thumbnails/18.jpg)
Assignment
• Modify TestServlet to show the current date.
• Study the servlet API documentation.
• Modify TestServlet to show initial parameters, and provide some of those.