Emulate Server

Client requests from Server; Server responds to Client

Install webserver (Apache, PHP & MySQL) such as XAMPP.

Start XAMPP and run Apache and MySQL. Check if your webserver is activated with PHP & MySQL by going to http://127.0.0.1 or http://localhost/ with a web browser. If that works, go to http://localhost/phpmyadmin/  or http://127.0.0.1/phpmyadmin/ . Then go to Databases and create a database, let’s call it my_db with utf8_general_ci.

Now, create a table for the database, give it a name (e.g. my_db_table) and 5 columns, then click the Go button.

For the Name column, give it 4 names, such as: fld_no, fld_title, fld_desc, fld_comment; with their types as INT and the rest as TEXT; give Length/Values to the INT 3 while leaving the rest for the TEXT blank. Then, click the Save button. Your table has been created in the database.

@ Home, click on User accounts tab. Click on Add user account.

Create a form.html with this code and place it in <drive:>\xampp\htdocs:

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>Contact Form - PHP/MySQL Demo Code</title>
</head>

<body>
	<fieldset>
	<legend>Contact Form</legend>
	<form name="frmContact" method="post" action="contact.php">
	<p>
	<label for="Name">Name </label>
	<input type="text" name="txtName" id="txtName">
	</p>
	<p>
	<label for="email">Email</label>
	<input type="text" name="txtEmail" id="txtEmail">
	</p>
	<p>
	<label for="phone">Phone</label>
	<input type="text" name="txtPhone" id="txtPhone">
	</p>
	<p>
	<label for="message">Message</label>
	<textarea name="txtMessage" id="txtMessage"></textarea>
	</p>
	<p>&nbsp;</p>
	<p>
	<input type="submit" name="Submit" id="Submit" value="Submit">
	</p>
	</form>
	</fieldset>
</body>

</html>

Apache Tomcat

Apache Tomcat server is a Java-capable (executes Java programs known as “Java Servlet” and “Java Server Pages (JSP)”) HTTP application (server).

It runs over TCP/IP (runs on a TCP port (default is port 80) of an IP address). For test HTTP server, use any unused port 1024~65535.

Tomcat 9 requires JDK 1.8 and later. You can check your JDK version via command “javac -version

Prerequisites:

  • Have JDK installed (generally @ C:\Program Files\Java)
    • Check version to install
    • Set JAVA_HOME Environment Variable
      • Windows 10 – Environment Variables > System variables > New > Variable name: JAVA_HOME; Variable value: <JDK installation path>
  • a

Tomcat is an open-source project under the Apache Software Foundation .

  1. Download and install (unzip/untar) Tomcat (can install multiple simultaneously, i.e. portable and main folder name can be changed)
  2. Configure (config files in conf folder)
    1. server.xml – (if want) change TCP 8080 default port number to any 1024 ~ 65535
    2. web.xml – in the <servlet-name>default <servlet> block, change listing’s <param-value> from false to true (
      1. this enables directory listing (useful for testing but not general use due to security reasons)
    3. context.xml – change <Context> to <Context reloadable=”true”> to enable automatic reload whenever code is changed (useful for testing but not general use due to overhead)
  3. Start server (files in bin folder)
    1. Run catalina.bat start to start server from cmd
    2. Visit http://localhost:<TCP port>/ at any browser, should see an opening page

Windows


Reference

  1. (n.d.). Medium – Where good ideas find you. https://medium.com/@ngotantien/how-to-install-apache-tomcat-9-on-windows-mac-os-x-ubuntu-and-get-started-with-java-servlet-45f959d7ee0a