Buddhikanip / Simple-Http-Server-Using-Java

This is a simple HTTP server implemented in Java that serves HTML and PHP files. It can handle both GET and POST requests and execute PHP scripts.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Simple HTTP Server Using Java

This is a simple HTTP server implemented in Java that serves HTML and PHP files. It can handle both GET and POST requests and execute PHP scripts.

Prerequisites

Before running the server, ensure you have the following:

  • Java Development Kit (JDK) installed.
  • PHP installed and added to your system's PATH (for PHP script execution).
  • Or else the php directory of your own wamp/mamp/xampp server should be given instead of php in line 141 of the code.
ProcessBuilder processBuilder = new ProcessBuilder("php", filePath, params);

How to run?

  1. Clone or download this repository to your local machine.

  2. Open a terminal or command prompt and navigate to the project directory.

  3. Compile the HttpServer.java file:

javac HttpServer.java
  1. Run the server:
java HttpServer
  1. The server will start listening on port 2728. You can access it in a web browser.http://localhost:2728/

Project Structure

  • HttpServer.java: The main Java server program.
  • add.php: A sample PHP script that performs addition based on POST or GET parameters.
  • index.html: A simple HTML form for submitting numbers to the add.php script.

Features

  • Handles GET and POST requests.
  • Serves static HTML files from the htdocs directory.
  • Executes PHP scripts and passes parameters.

Configuration

You can modify the server's behavior by editing the HttpServer.java file. For example, you can change the port number, the root directory for HTML files (htdocs), or add more handling logic for different HTTP methods or file types. Any other resources that you wish to include can be added to the htdocs folder as well.

License

This project is licensed under the GNU License - see the LICENSE file for details.

Acknowledgments

This project was created as a simple example of a Java-based HTTP server with PHP support. It can be used as a starting point for more complex web server applications or educational purposes.

License: GNU Hits Tests Passing GitHub Contributors Issues GitHub pull requests

About

This is a simple HTTP server implemented in Java that serves HTML and PHP files. It can handle both GET and POST requests and execute PHP scripts.

License:GNU General Public License v3.0


Languages

Language:Java 73.9%Language:HTML 13.6%Language:PHP 12.5%