# basic-servlet **Repository Path**: java-lesson/basic-servlet ## Basic Information - **Project Name**: basic-servlet - **Description**: No description available - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-04-06 - **Last Updated**: 2026-04-06 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Basic Servlet Project A Java Web basic project based on Jakarta Servlet, used for learning and demonstrating core Servlet functionalities. ## 📋 Introduction This project is a simple Java Web application that demonstrates the basic usage of Servlets, including: - HTTP request handling (GET/POST) - Form parameter retrieval - File upload functionality - User login validation ## 🛠️ Technology Stack - **Java**: JDK 26 - **Servlet**: Jakarta Servlet API 6.1.0 - **Build Tool**: Maven - **File Upload**: Commons FileUpload 2.0.0-M4 - **Package Format**: WAR ## 📁 Project Structure ``` basic-servlet/ ├── src/ │ ├── main/ │ │ ├── java/com/example/basic/servlet/ │ │ │ ├── HelloServlet.java # Greeting example Servlet │ │ │ ├── LoginServlet.java # Login validation Servlet │ │ │ ├── RegisterServlet.java # Registration parameter handling Servlet │ │ │ └── UploadPhotoServlet.java # File upload Servlet │ │ └── webapp/ │ │ ├── WEB-INF/ │ │ │ └── web.xml # Web application configuration │ │ ├── index.jsp # Home page │ │ ├── login.html # Login page │ │ ├── register.html # Registration page │ │ └── upload.html # File upload page ├── pom.xml # Maven configuration file └── README_EN.md # Project documentation (English) ``` ## 🚀 Quick Start ### Prerequisites - JDK 26 or higher - Maven 3.6+ - Servlet container (e.g., Tomcat 10+) ### Build Project ```bash mvn clean package ``` After building, a `basic-servlet-1.0-SNAPSHOT.war` file will be generated in the `target` directory. ### Deployment 1. Copy the generated WAR file to Tomcat's `webapps` directory 2. Start the Tomcat server 3. Visit http://localhost:8080/basic-servlet-1.0-SNAPSHOT/ ### Development Mode Import the Maven project using an IDE (such as IntelliJ IDEA), configure the Tomcat server, and run directly. ## 📝 Features ### 1. Hello Servlet - **Path**: `/hello-servlet` - **Method**: GET - **Function**: Display a simple greeting message - **Description**: Demonstrates basic Servlet initialization and response output ### 2. User Login - **Path**: `/login` - **Method**: POST - **Function**: Validate username and password - **Test Account**: - Username: `admin` - Password: `123` - **Description**: Demonstrates POST request handling and simple authentication ### 3. User Registration - **Path**: `/register` - **Method**: GET/POST - **Function**: Demonstrate multiple parameter retrieval methods - Single value parameter retrieval (`getParameter`) - Multi-value parameter retrieval (`getParameterValues`) - Iterate through all parameters (`getParameterMap`) - **Description**: Shows how to handle different types of form data ### 4. File Upload - **Path**: `/uploadPhoto` - **Method**: POST - **Function**: Receive and save uploaded files - **Limit**: Maximum file size 1MB - **Storage Location**: `webapp/uploaded/` directory - **Description**: Demonstrates multipart/form-data file upload handling ## 🔧 Configuration ### Maven Dependencies The project uses the following main dependencies: - `jakarta.servlet-api`: Servlet API (provided scope) - `commons-fileupload2-jakarta-servlet6`: File upload support ### Compilation Configuration - Source encoding: UTF-8 - Java version: 26 ## 📌 Notes 1. **Character Encoding**: All Servlets are set to UTF-8 encoding to ensure proper display of Chinese characters 2. **File Upload**: Uploaded files are saved in the `uploaded` directory, please ensure this directory has write permissions 3. **Security**: This project is for learning purposes only. Production environments require more comprehensive security measures 4. **Temporary File Cleanup**: Temporary files are cleaned up after file upload to avoid disk space占用 ## 🤝 Contributing Issues and Pull Requests are welcome! ## 📄 License This project is for educational purposes only. ## 📧 Contact If you have any questions, please report them via Issues.