Download presentation
Presentation is loading. Please wait.
Published byArleen Wilson Modified over 9 years ago
1
Web Server Programming 1. Nuts and Bolts
2
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
3
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
4
Contents of this course Web technology: protocols & languages Web server: request handling, output generation, session & user management Server programming: –Java servlets –JSP
5
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.)
6
About the Web Reinier Post
7
JAVA Support Component based Platform independent Built-in security Software libraries for every application
8
Web Applications Cooperating parts: –(HTML) documents –Servlets –JSP pages –Applets (client side software) Common context –Properties (appl. param., configuration data) –Resources (shared data)
9
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
10
JSP Pages Based on HTML or XML Contain processing tags Use servlet classes Converted to servlet
11
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)
12
Servlet API Interface Servlet Interface ServletConfig Interface ServletContext Interface ServletRequest Interface ServletResponse
13
Interface Servlet Init() Service() Destroy() getServletConfig() getServletInfo()
14
Class HttpServlet Inherits from GenericServlet (impl. Servlet) Additional methods: –doGet() –doPost() –doHead() –doDelete() –doOptions() –doTrace()
15
Requests and Responses Interface HttpServletRequest –Request as stream –HTTP headers –Parameters –Path info Interface HttpServletResponse –Output stream –HTTP headers –Cookies
16
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
17
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(" ");.. out.println(" "); } //Clean up resources public void destroy() { }
18
Assignment Modify TestServlet to show the current date. Study the servlet API documentation. Modify TestServlet to show initial parameters, and provide some of those.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.