COMP S834 Web Server Technology Embedded interpreters often come with other

Comp s834 web server technology embedded interpreters

This preview shows page 24 - 27 out of 65 pages.

COMP S834 Web Server Technology Embedded interpreters often come with other features designed to improve performance. For example, the PHP embedded interpreter also offers code caching: scripts are loaded and compiled only once, when the Web server is first started. The scripts are served from the Web server’s cache for subsequent requests. Running pre-compiled code results in faster execution times than running interpreted code. The mod_perland mod_phpApache modules are examples of embedded interpreters. Whenever possible, we recommended using embedded interpreters over plain CGI when running server-side scripts. This is the approach we shall use for ABC Books, our case study website. For example, below is the PHP script that reads the server’s environment variables (HTTP_USER_AGENT&REQUEST_METHOD) and writes their values into the HTML webpage. <html> <body> <?php echo $_SERVER['HTTP_USER_AGENT']; echo "<br>"; echo $_SERVER['REQUEST_METHOD']; ?> </body> </html> Servlets Just like CGI scripts, servlets are programs running on the Web server which can respond to HTTP requests. For example, below is the servlet program that reads the form data (i.e. name) sent from the client using the HTTP POST method and writes the value into the HTML webpage. import javax.servlet.http.*; public class test extends HttpServlet{ public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException{ Response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html><body>"); out.println("Name="+request.getParameter("name")+"<br>"); out.println("</body></html>");} Servlets are written in the Java programming language, and their main advantage over CGI is that only one copy of a servlet class is needed to service multiple requests. Servlets are multithreaded, which means that the processor handles new, incoming requests by launching lightweight Java threads instead of a separate operating system process. Servlets also remain in memory after they finish processing, so they can store information in between requests, such as results of previous computations.
Background image
Unit 3 21Unlike CGI, support for Java servlets is not universal. For example, Microsoft’s IIS does not include native support for Java servlets. However, there are add-on engines available that let IIS support Java Servlets. Java servlets can also be executed using a stand-alone server, such as Apache Tomcat. At this point, test your understanding of executing server-side applications in the following self-test. Self-test 3.3 1 What kind of data is passed by the Web server to the server-side program? 2 Compare the advantages/disadvantages of using interpreted versus compiled languages for server programming. 3 Compare the advantages/disadvantages of the different Web server extension mechanisms we just discussed.
Background image
22COMP S834 Web Server Technology Developing server-side applications We have spent most of this unit discussing the inner workings of server-side programs: how data is submitted to them, how the Web server
Background image
Image of page 27

You've reached the end of your free preview.

Want to read all 65 pages?

  • Spring '18
  • World Wide Web, Web server, Hypertext Transfer Protocol, Server-side scripting

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes