Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SpringBasedCrud

A minimal Spring MVC + JSP CRUD application for managing users records using JdbcTemplate and a container-managed JNDI datasource.

Tech Stack

  • Java 17
  • Maven (WAR packaging)
  • Spring MVC 6.1
  • JSP/Servlet (Jakarta EE 6)
  • JDBC via JdbcTemplate

Application Flow

web.xml registers DispatcherServlet -> dispatcher-servlet.xml wires Spring MVC beans -> CrudController handles routes -> CrudService runs SQL -> index.jsp renders form and table.

Main Files Added and Purpose

  • pom.xml: Maven build, dependencies (spring-webmvc, spring-jdbc, jakarta.servlet-api), and WAR packaging.
  • src/main/webapp/WEB-INF/web.xml: Registers DispatcherServlet and maps all requests (/) to Spring MVC.
  • src/main/webapp/WEB-INF/dispatcher-servlet.xml: Spring MVC config (component scan, view resolver, datasource, JdbcTemplate).
  • src/main/resources/application.properties: Externalized app settings (currently datasource JNDI name).
  • src/main/java/org/springbasedcrud/CrudController.java: Web controller for list/create/update/delete endpoints.
  • src/main/java/org/springbasedcrud/CrudService.java: Service layer executing SQL statements with JdbcTemplate.
  • src/main/java/org/springbasedcrud/Users.java: Model/POJO representing a user row.
  • src/main/webapp/WEB-INF/views/index.jsp: UI page with create/update form, users table, and delete action.

Components in dispatcher-servlet.xml

  • <context:component-scan ...>: Detects @Controller and @Service classes in org.springbasedcrud.
  • <context:property-placeholder ...>: Loads values from application.properties.
  • <mvc:annotation-driven/>: Enables @GetMapping, @PostMapping, binding, and MVC defaults.
  • InternalResourceViewResolver: Resolves view names like index to /WEB-INF/views/index.jsp.
  • JndiObjectFactoryBean (dataSource): Looks up datasource from app server JNDI.
  • JdbcTemplate: Provides simplified JDBC operations using the configured datasource.

Local Setup Changes Required

  1. Install prerequisites:
    • JDK 17
    • Maven 3.9+
    • Servlet container/app server (Tomcat/JBoss/WildFly) that supports Jakarta Servlet 6
  2. Create database/table expected by SQL in CrudService:
CREATE TABLE users (
  id INT PRIMARY KEY AUTO_INCREMENT,
  name VARCHAR(100) NOT NULL,
  age INT NOT NULL,
  email VARCHAR(150) NOT NULL,
  location VARCHAR(120) NOT NULL
);
  1. Configure a datasource in your app server and expose it via JNDI.
  2. Update src/main/resources/application.properties if your JNDI name differs:
    • app.datasource.jndi-name=java:jboss/datasources/MysqlDS
  3. Build and deploy:
mvn clean package

Deploy target/springbasedcrud.war to your server.

Endpoints

  • GET /test: Health check text response.
  • GET /users: List users and optionally open edit mode (?editId=<id>).
  • POST /users/save: Create or update user.
  • POST /users/{id}/delete: Delete user.

About

Spring application for Crud Operation

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages