YourNote 202: Project Structure - zhamri/CSC584-Enterprise_Programming GitHub Wiki
MyWebApp/
│
├── src/ → Java source files
│ └── com/example/
│ ├── servlet/
│ │ └── LoginServlet.java
│ ├── model/
│ │ └── User.java
│ └── dao/
│ └── UserDAO.java
│
├── WebContent/ (or webapp/) → Web resources
│ ├── index.jsp
│ ├── login.jsp
│ ├── home.jsp
│ │
│ ├── css/
│ │ └── style.css
│ ├── js/
│ │ └── script.js
│ │
│ └── WEB-INF/
│ ├── web.xml
│ ├── lib/ → external JAR files
│ └── classes/ → compiled .class files (auto-generated)
│
└── build/ (or target/) → compiled output (if using Maven/Gradle)
Organize using packages
-
servlet/→ all Servlets (controller layer) -
model/→ JavaBean / POJO (data) -
dao/→ database access (JDBC)
This follows MVC pattern:
- Model → model
- View → JSP
- Controller → Servlet
This is what the browser can access.
Common files:
-
index.jsp→ entry page -
.jspfiles → UI (View) -
css/,js/→ frontend assets
This folder is NOT accessible directly via browser.
Contains:
-
web.xml→ deployment descriptor (Servlet mapping) -
lib/→ JAR dependencies. Example:- mysql-connector-j-8.0.33.jar
- jakarta.servlet-api-6.0.0.jar
- commons-lang3-3.13.0.jar
-
classes/→ compiled Java classes
Example:
http://localhost:8080/MyWebApp/WEB-INF/web.xml ❌ NOT ALLOWED
Example:
<web-app>
<servlet>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>com.example.servlet.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
</web-app>If you want a cleaner + industry style, use Maven
MyWebApp/
│
├── src/
│ ├── main/
│ │ ├── java/
│ │ │ └── com/example/...
│ │ │
│ │ ├── webapp/
│ │ │ ├── index.jsp
│ │ │ └── WEB-INF/
│ │ │ └── web.xml
│ │ │
│ │ └── resources/
│ │
│ └── test/
│
├── pom.xml
└── target/
This is the structure used in:
- enterprise apps
- CI/CD pipelines (GitHub Actions, Jenkins)
- Docker deployments
MyWebApp/
│
├── src/
│ └── LoginServlet.java
│
├── WebContent/
│ ├── index.jsp
│ ├── result.jsp
│ └── WEB-INF/
│ └── web.xml
| Feature | webapp | WebContent |
|---|---|---|
| Used by | Maven / Gradle | Eclipse (Dynamic Web Project) |
| Standard | ✅ Yes (industry) | ❌ No (IDE-specific) |
| Modern? | ✅ Yes | ❌ Older |
| Recommended? | ✅ YES | OK for beginners |
- Always separate:
- Servlet (logic)
- JSP (UI)
- ❌ Do NOT write ALL Java code inside JSP (bad practice)
- Use packages (com.uum.student)
- Follow MVC pattern
- Use meaningful folder names