Expense Manager Project using Spring Framework

Expense Manager Project using Spring Framework:

Login Screen:

Register Screen:

Profile Screen:

Add Expense Screen:

List of Expense Screen:

Edit Expense Screen:

Project Structure:

AppConfig .java


package com.example.config;
import java.util.concurrent.TimeUnit;
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.http.CacheControl;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewResolverRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

@Configuration
@ComponentScan(basePackages = { "com.example" })
@EnableWebMvc
@PropertySource(value = { "classpath:data.properties" })
public class AppConfig implements WebMvcConfigurer {
            
@Autowired
private Environment environment;
            
@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
registry.jsp("/WEB-INF/views/", ".jsp");
}
            
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
// Register resource handler for images
registry.addResourceHandler("/images/**").addResourceLocations("/images/")
.setCacheControl(CacheControl.maxAge(0, TimeUnit.HOURS).cachePublic());
registry.addResourceHandler("/profileimage/**").addResourceLocations("/profileimage/")
.setCacheControl(CacheControl.maxAge(0, TimeUnit.HOURS).cachePublic());
}
            
@Bean
public DataSource dataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName(environment.getRequiredProperty("jdbc.class"));
dataSource.setUrl(environment.getRequiredProperty("jdbc.url"));
dataSource.setUsername(environment.getRequiredProperty("jdbc.user"));
dataSource.setPassword(environment.getRequiredProperty("jdbc.pass"));
System.out.println("Deep database " + dataSource);
return dataSource;
}
            
@Bean
public JdbcTemplate getJdbcTemplate() {
return new JdbcTemplate(dataSource());
}
            
@Bean
public CommonsMultipartResolver multipartResolver() {
CommonsMultipartResolver cm = new CommonsMultipartResolver();
cm.setMaxUploadSize(5008528);
return cm;
}
            
}

FrontController.java


package com.example.controller;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
import com.example.config.AppConfig;

public class FrontController extends AbstractAnnotationConfigDispatcherServletInitializer {

@Override
protected Class<?>[] getRootConfigClasses() {
return new Class[] { AppConfig.class };
}

@Override
protected Class<?>[] getServletConfigClasses() {
// TODO Auto-generated method stub
return null;
}

@Override
protected String[] getServletMappings() {
return new String[] {"/"};
}

}

ProductController .java


package com.example.controller;
import java.util.List;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.example.dao.ProductDao;
import com.example.model.Product;
import com.example.model.User;

@Controller
public class ProductController {

@Autowired
private ProductDao productDao;

@GetMapping("/")
public String mainPage() {
return "index";
}

@GetMapping("addexpense")
public String addExpenses() {
return "addexpense";
}

@PostMapping("addexpenseprocess")
public String addExpensesProcess(Product product, Model model,HttpSession session) {
int i = productDao.insert(product,((User)session.getAttribute("user")).getExpensetable());
if (i > 0) {
model.addAttribute("msg", "Successfully Added");
}else {
model.addAttribute("msg", "Added Failed");
}
return "addexpense";
}

@GetMapping("listofexpenses")
public String expenseList(Model model,HttpSession session) {

List<Product>list=productDao.getAllExpenses(((User)session.getAttribute("user")).getExpensetable());
model.addAttribute("exp",list);
return "listofexpenses";
}

@PostMapping("delete/{id}")
public String deleteExpense(@PathVariable() int id,HttpSession session) {
int i=productDao.deleteExpense(id,((User)session.getAttribute("user")).getExpensetable());
return "redirect:/listofexpenses";
}

@PostMapping("update")
public String updateExpense(Product product,HttpSession session) {
int i=productDao.updateExpense(product,((User)session.getAttribute("user")).getExpensetable());
return "redirect:/listofexpenses";
}

}

UserController .java


package com.example.controller;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import com.example.dao.ProductDao;
import com.example.dao.UserDao;
import com.example.model.User;

@Controller
public class UserController {

@Autowired
private UserDao userDao;

@Autowired
private ProductDao productDao;

@PostMapping("login")
public String login(@RequestParam String email, @RequestParam String pass, Model model, HttpSession session) {
User user = userDao.login(email, pass);
if (user != null) {
session.setAttribute("user", user);
return "redirect:/homepage";
} else {
model.addAttribute("msg", "Invalid Email or Password");
return "index";
}
}

@GetMapping("/homepage")
public String homePage() {
return "homepage";
}

@PostMapping("/register")
public ModelAndView register(User user) {
int i = userDao.insert(user);
ModelAndView m = new ModelAndView();
if (i > 0) {
String tablename="exp"+String.valueOf(System.currentTimeMillis());
productDao.createTable(tablename);
user.setExpensetable(tablename);
userDao.updateProfile(user);
m.addObject("msg", "Successfully Registerd");
} else {
m.addObject("msg", "Registerd Failed");
}
m.setViewName("index");
return m;
}

@GetMapping("profile")
public String profile() {
return "profile";
}

@PostMapping("profileProcess")
public String profileProcess(@RequestParam("imageprofile") MultipartFile file,HttpSession session) {
String rootlocation=session.getServletContext().getRealPath("/");
File folder=new File(rootlocation,"profileimage");
folder.mkdir();

User user=(User)session.getAttribute("user");

File filename=new File(folder,user.getEmail()+".jpg");

if(!file.isEmpty()) {
try {
byte [] bytes=file.getBytes();
FileOutputStream fo=new FileOutputStream(filename);
fo.write(bytes);
fo.close();
user.setProfileimage(user.getEmail()+".jpg");
int i=userDao.updateProfile(user);
System.out.println(filename.getAbsolutePath());
} catch (IOException e) {
System.out.println(e);
}
}
return "redirect:/profile";
}

@GetMapping("logout")
public String logout( HttpSession session) {
session.removeAttribute("user");
session.invalidate();
return "redirect:/";
}

}

ProductDao .java


package com.example.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;
import com.example.model.Product;

@Repository
public class ProductDao {

@Autowired
private JdbcTemplate jdbcTemplate;

public void createTable(String tablename) {
jdbcTemplate.execute("create table "+tablename+" (id int NOT NULL AUTO_INCREMENT,name varchar(25) NOT NULL,price
float,quantity int,date varchar(20),PRIMARY KEY (id))");
}

public int insert(Product product, String tablename) {
return jdbcTemplate.update("insert into " + tablename + " values(default,?,?,?,?)",
new Object[] { product.getName(), product.getPrice(), product.getQuantity(), product.getDate() });
}

public int deleteExpense(int id, String tablename) {
return jdbcTemplate.update("delete from " + tablename + " where id=?", new Object[] { id });
}

public int updateExpense(Product product, String tablename) {
return jdbcTemplate.update("update " + tablename + " set name=?, price=?, quantity=?, date=? where id=?",
new Object[] { product.getName(), product.getPrice(), product.getQuantity(), product.getDate(),
product.getId() });
}

public List<Product> getAllExpenses(String tablename) {
return jdbcTemplate.query("select * from " + tablename + " ", new ProductRowMapper());
}

class ProductRowMapper implements RowMapper<Product> {

@Override
public Product mapRow(ResultSet rs, int rowNum) throws SQLException {
Product product = new Product();
product.setId(rs.getInt(1));
product.setName(rs.getString(2));
product.setPrice(rs.getFloat(3));
product.setQuantity(rs.getInt(4));
product.setDate(rs.getString(5));
return product;
}

}

}

UserDao .java


package com.example.dao;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;
import com.example.model.User;

@Repository
public class UserDao {

@Autowired
private JdbcTemplate jdbcTemplate;

public int insert(User user) {
return jdbcTemplate.update("insert into user values(?,?,?,?,?)",
new Object[] { user.getName(), user.getEmail(), user.getPass(),user.getProfileimage(),user.getExpensetable() });
}

public int updateProfile(User user) {
return jdbcTemplate.update("update user set name=?,pass=?,profile=?,expensetable=? where email=?",
new Object[] { user.getName(), user.getPass(), user.getProfileimage(),user.getExpensetable(), user.getEmail() });
}

public User login(String email, String pass) {
User user = null;
List<User> users = jdbcTemplate.query("select * from user where email=? and pass=?",
new Object[] { email, pass }, new MyRowMapper());
if (users.size() > 0) {
user = users.get(0);
}
return user;
}

private class MyRowMapper implements RowMapper<User> {

@Override
public User mapRow(ResultSet rs, int rowNum) throws SQLException {
User user = new User();
user.setName(rs.getString(1));
user.setEmail(rs.getString(2));
user.setPass(rs.getString(3));
user.setProfileimage(rs.getString(4));
user.setExpensetable(rs.getString(5));
return user;
}

}
}

Product.java


package com.example.model;
import org.springframework.stereotype.Component;

@Component
public class Product {
private String name;
private float price;
private int quantity;
private String date;
private int id;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public float getPrice() {
return price;
}

public void setPrice(float price) {
this.price = price;
}

public int getQuantity() {
return quantity;
}

public void setQuantity(int quantity) {
this.quantity = quantity;
}

public String getDate() {
return date;
}

public void setDate(String date) {
this.date = date;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

}

User.java


package com.example.model;
import org.springframework.stereotype.Component;

@Component
public class User {
private String email;
private String pass;
private String name;
private String profileimage;
private String expensetable;


public String getExpensetable() {
return expensetable;
}

public void setExpensetable(String expensetable) {
this.expensetable = expensetable;
}

public String getProfileimage() {
return profileimage;
}

public void setProfileimage(String profileimage) {
this.profileimage = profileimage;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public String getPass() {
return pass;
}

public void setPass(String pass) {
this.pass = pass;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

}

data.properties


jdbc.url=jdbc:mysql://localhost:3306/expensespring
jdbc.class=com.mysql.jdbc.Driver
jdbc.pass=root
jdbc.user=root

addexpenses.jsp


<%@include file="head.jsp" %>
    <form action="addexpenseprocess" method="post" style="height: 90vh;">
        <div class="row" style="margin: 1px;">

            <div class="col-sm-1"></div>

            <div class="col-sm-10" style="box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2); transition: 0.3s;">

                <h1 align="center">Add Expense Here</h1>
                <div align="center">
                    <b>${msg}</b>
                </div>
                <hr>

                <div class="col-md-2"></div>

                <div class="col-md-4">
                    <br>
                    <div class="form-group">
                        <label for="name">Product Name:</label> <input type="text" class="form-control" id="name"
                            placeholder="Enter Name" autocomplete="off" name="name" required="required">
                    </div>
                    <div class="form-group">
                        <label for="price">Product Price:</label> <input type="number" step="0.1" class="form-control"
                            id="price" placeholder="Enter Price" name="price" required="required">
                    </div>
                </div>


                <div class="col-md-4">
                    <br>>
                    <div class="form-group">
                        <label for="quantity">Product Quantity</label> <input type="number" class="form-control"
                            id="quantity" min="1" name="quantity" required="required" placeholder="Enter Quantity">
                    </div>
                    <div class="form-group">
                        <label for="date">Product Date:</label> <input type="date" class="form-control" id="date"
                            name="date" required="required">
                    </div>

                </div>


                <div class="form-inline">

                    <div class="row" style="box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2); transition: 0.3s;">
                        <div class="col-sm-3"></div>
                        <div class="col-sm-6" align="center">
                            <br>
                            <button type="submit" class="btn btn-primary" style="width: 100%;">Add
                                Expenses</button>
                            <br> <br> <br>
                        </div>
                        <div class="col-sm-2"></div>
                    </div>
                </div>

            </div>

        </div>

    </form>

    <%@include file="foot.jsp" %>

    

homepage.jsp

        
        <%@include file="head.jsp" %>
            
                <div class="row" style="margin: 1px;height: 90vh;">
        
                    <div class="col-sm-4"></div>
        
                    <div class="col-sm-6"></div>
        
                </div>
        
                <%@include file="foot.jsp" %>

    

foot.jsp

        
            <div style="background: black;" align="center">
                <b style="color: white; font-family: serif; text-align: center;font-size: large;">All
                    right reserve © deepsingh44.blogspot.com</b>
            </div>
        
    

head.jsp

        
    <%@taglib prefix="p" uri="http://java.sun.com/jsp/jstl/core" %>
    
        <head>
            <title>Expense App</title>
            <meta name="viewport" content="width=device-width, initial-scale=1">
            <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
            <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"/>
            <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"/>
    
        </head>
    
        <nav class="navbar navbar-inverse">
            <div class="container-fluid">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
                    <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span>
                    </button>
                    <a class="navbar-brand" href="#">Expense App</a>
                </div>
                <div class="collapse navbar-collapse" id="myNavbar">
    
                    <p:choose>
                        <p:when test="${sessionScope.user ne null}">
                            <ul class="nav navbar-nav navbar-right">
                                <li><a href="home">Home</a></li>
                                <li><a href="profile">Profile</a></li>
                                <li><a href="addexpense">Add Expense</a></li>
                                <li><a href="listofexpenses">Expense List</a></li>
                                <li><a href="logout">Logout</a></li>
                            </ul>
                        </p:when>
                    </p:choose>
    
                </div>
            </div>
        </nav>
        
    

index.jsp

        
            <head>
            <script
            
            src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
            <script
            
            src="https://unpkg.com/@lottiefiles/lottie-player@latest/dist/lottie-player.js"></script>
            
            <script type="text/javascript">
            $(document).ready(function() {
            $("#regbtn").click(function() {
            $("#login").css("display", "none");
            $("#register").css("display", "block");
            });
            
            $("#logbtn").click(function() {
            $("#register").css("display", "none");
            $("#login").css("display", "block");
            });
            
            $("#lgbtn").click(function() {
            var email = $("#email").val();
            var pass = $("#pwd").val();
            
            if (email == "") {
            alert("Please enter email id");
            /* $("#email").focus().css("border-color","red"); */
            } else if (pass == "") {
            alert("Please enter password");
            /* $("#pwd").focus().css("border-color","red"); */
            } else {
            $.post("login", {
            email : email,
            pass : pass,
            }, function(response) {
            $("body").html(response);
            });
            }
            });
            
            $("#rgbtn").click(function() {
            var name = $("#name").val();
            var email = $("#remail").val();
            var pass = $("#rpwd").val();
            
            if (name == "") {
            alert("Please enter full name");
            /* $("#email").focus().css("border-color","red"); */
            }else if (email == "") {
            alert("Please enter email id");
            /* $("#email").focus().css("border-color","red"); */
            } else if (pass == "") {
            alert("Please enter password");
            /* $("#pwd").focus().css("border-color","red"); */
            } else {
            $.post("register", {
            name:name,
            email : email,
            pass : pass,
            }, function(response) {
            $("body").html(response);
            });
            }
            });
            
            });
            </script>
            </head>
            <%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
            <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
            <body
            style="background-image: url('<spring:url value="/images/back.jpg"/>');background-size:
            cover;width:100%;">
            <%@include file="head.jsp"%>
            
            <br>
            <div class="row" style="margin: 1px;">
            
            <div class="col-sm-4" align="center">
            <lottie-player
            src="https://assets2.lottiefiles.com/packages/lf20_LnBl3M.json"
            background="transparent" speed="2"
            style="width: 300px; height: 300px;" loop autoplay></lottie-player>
            <br> <br>
            </div>
            
            <div class="col-sm-3">
            <b>${msg}</b>
            </div>
            
            <div class="col-sm-4" id="login"
            style="box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2); transition: 0.3s; background: white; border-radius:
            10px;">
            <h1 align="center">Login Detail</h1>
            <hr>
            <%-- <form action="login" method="post"> --%>
            <div class="form-group">
            <label for="email">Email address:</label> <input type="email"
            class="form-control" id="email" placeholder="Enter Email"
            name="email">
            </div>
            <div class="form-group">
            <label for="pwd">Password:</label> <input type="password"
            class="form-control" id="pwd" placeholder="Enter Password"
            name="pass">
            </div>
            <div class="checkbox">
            <label><input type="checkbox"> Remember me</label>
            </div>
            <button type="button" class="btn btn-primary" id="lgbtn"
            style="width: 100%;">Login</button>
            <div style="width: 100%;">
            <div style="width: 40%; float: left;">
            <hr>
            </div>
            <div
            style="width: 20%; float: left; text-align: center; line-height: 40px;">
            <b>OR</b>
            </div>
            <div style="width: 40%; float: right;">
            <hr>
            </div>
            </div>
            <button type="button" class="btn btn-primary" id="regbtn"
            style="width: 100%;">For new user click here</button>
            <br> <br> <br> <br>
            <%-- </form> --%>
            </div>
            
            <div class="col-sm-4" id="register"
            style="box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2); transition: 0.3s; background: white; border-radius: 10px;
            display: none;">
            <h1 align="center">Register Detail</h1>
            <hr>
            <%-- <form action="register" method="post"> --%>
            
            <div class="form-group">
            <label for="name">Full Name:</label> <input type="text"
            class="form-control" id="name" placeholder="Enter Name"
            name="name">
            </div>
            
            <div class="form-group">
            <label for="email">Email address:</label> <input type="email"
            class="form-control" id="remail" placeholder="Enter Email"
            name="email">
            </div>
            <div class="form-group">
            <label for="pwd">Password:</label> <input type="password"
            class="form-control" id="rpwd" placeholder="Enter Password"
            name="pass">
            </div>
            
            <button type="button" class="btn btn-primary" id="rgbtn" style="width:
            100%;">Submit</button>
            <div style="width: 100%;">
            <div style="width: 40%; float: left;">
            <hr>
            </div>
            <div
            style="width: 20%; float: left; text-align: center; line-height: 40px;">
            <b>OR</b>
            </div>
            <div style="width: 40%; float: right;">
            <hr>
            </div>
            </div>
            <button type="button" class="btn btn-primary" id="logbtn"
            style="width: 100%;">For existence user click here</button>
            <br> <br>
            <%-- </form> --%>
            </div>
            
            <div class="col-sm-1"></div>
            </div>
            
            </body>
        
    

listofexpenses.jsp


    <head>
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons"
    rel="stylesheet">
    <script
    
    src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script type="text/javascript">
    $(document).ready(function() {
    
    $("#search").on("keyup", function() {
    var value = $(this).val().toLowerCase();
    $("table tbody .tr").filter(function() {
    $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
    });
    });
    
    var id;
    $("table tbody .tr td").click(function() {
    var text = $(this).find("button").text();
    
    if (text == "") {
    
    } else {
    id= $(this).closest(".tr").find('td.id')
    .text();
    
    var name = $(this).closest(".tr").find('td.name')
    .text();
    
    var price = $(this).closest(".tr").find('td.price')
    .text();
    
    var quantity = $(this).closest(".tr").find(
    'td.quantity').text();
    
    var date = $(this).closest(".tr").find('td.date')
    .text();
    
    if (text == "Edit") {
    $("#pname").val(name);
    $("#pprice").val(price);
    $("#pquantity").val(quantity);
    $("#pdate").val(date);
    $('#myModal1').modal('show');
    
    } else {
    /* $('#myModal2').modal('show'); */
    if (confirm("Are you sure you want to delete this expense?")) {
    $.post("delete/"+ id,{},function(response) {
    location.reload();
    });
    } else {
    return false;
    }
    }
    }
    
    });
    
    $("#updbutton").click(function(){
    
    var name=$("#pname").val();
    var price=$("#pprice").val();
    var quantity=$("#pquantity").val();
    var date=$("#pdate").val();
    
    if(name==""){
    alert("please enter product name");
    $("#pname").focus().css("border-color","red");
    }else if(price==""){
    alert("please enter product price");
    $("#pprice").focus().css("border-color","red");
    }else if(quantity==""){
    alert("please enter product quantity");
    $("#pquantity").focus().css("border-color","red");
    }else if(date==""){
    alert("please select product purchasing date");
    $("#pdate").focus().css("border-color","red");
    }else{
    $.post("update",{
    id:id,
    name:name,
    price:price,
    quantity:quantity,
    date:date,
    },function(response){
    location.reload();
    $('#myModal1').modal('hide');
    });
    }
    
    });
    
    });
    </script>
    
    </head>
    
    <%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
    <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
    <%@taglib prefix="p" uri="http://java.sun.com/jsp/jstl/core"%>
    <%@include file="head.jsp"%>
    <div class="container-fluid" align="center">
    <div
    style="width: 85%; box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2); transition: 0.3s;height: 85vh;">
    <div class="row">
    
    <div class="col-sm-4">
    <h1 align="center">List of Expenses</h1>
    </div>
    <div class="col-sm-4"></div>
    <div class="col-sm-4">
    <div class="form-group">
    <div align="center"
    style="display: flex; align-items: center; border: 1px lightgray solid; border-radius: 5px; margin-right: 10px;
    margin-left: 10px; margin-top: 20px;">
    <input type="text" class="form-control" style="border: 0;"
    id="search" name="search"
    placeholder="Search Expenses"><span
    class="material-icons"> search </span>
    </div>
    </div>
    
    </div>
    </div>
    <hr>
    
    <div class="row">
    
    <div class="col-sm-10">
    
    <div class="container" style="width: 90%;">
    
    <p:choose>
    <p:when test="${requestScope.exp.size() gt 0}">
    
    <table class="table table-hover">
    <thead>
    <tr>
    <th>ID</th>
    <th>NAME</th>
    <th>PRICE</th>
    <th>QUANTITY</th>
    <th>DATE</th>
    <th>Edit</th>
    <th>Delete</th>
    </tr>
    </thead>
    <tbody>
    
    <p:forEach items="${requestScope.exp}" var="product">
    
    <tr class="tr">
    <td class="id">${product.id}</td>
    <td class="name">${product.name}</td>
    <td class="price">${product.price}</td>
    <td class="quantity">${product.quantity}</td>
    <td class="date">${product.date}</td>
    <td><button class="btn btn-primary">Edit</button></td>
    <td>
    <button class="btn btn-danger">Delete</button>
    </td>
    </tr>
    
    
    
    
    </p:forEach>
    </tbody>
    </table>
    
    </p:when>
    
    <p:otherwise>
    <h1 align="center">There is no Expense!!</h1>
    </p:otherwise>
    
    </p:choose>
    
    </div>
    
    
    </div>
    </div>
    
    </div>
    
    <!-- Edit Modal -->
    
    <div id="myModal1" class="modal fade" role="dialog">
    <div class="modal-dialog modal-lg">
    
    <!-- Modal content-->
    <div class="modal-content">
    <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal">×</button>
    <h1 class="modal-title">Edit Expense</h1>
    </div>
    <div class="modal-body" align="left">
    <div class="row">
    <div class="col-sm-6">
    <div class="form-group">
    <label for="email">Product Name:</label> <input type="text"
    class="form-control" id="pname" placeholder="Product Name">
    </div>
    <div class="form-group">
    <label for="pwd">Product Price:</label> <input type="number"
    class="form-control" id="pprice" placeholder="Product Price">
    </div>
    </div>
    
    
    <div class="col-sm-6">
    <div class="form-group">
    <label for="email">Product Quantity:</label> <input
    type="number" class="form-control" id="pquantity"
    placeholder="Product Quantity">
    </div>
    <div class="form-group">
    <label for="email">Purchase Date:</label> <input type="date"
    class="form-control" id="pdate">
    </div>
    </div>
    
    <div align="center">
    <button type="submit" class="btn btn-primary" style="width: 60%;"
    id="updbutton">Update
    Expense</button>
    </div>
    
    </div>
    
    </div>
    
    </div>
    </div>
    
    </div>
    </div>
    
    <br>
    <%@include file="foot.jsp"%>  
    

profile.jsp


        <head>
        <link href="https://fonts.googleapis.com/icon?family=Material+Icons"
        rel="stylesheet">
        <script
        
        src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
        <script type="text/javascript">
        $(document).ready(function() {
        $("#off").click(function() {
        /* const type = $("#password").getAttribute('type') === 'password' ? 'text' :
        'password';
        $("#password").setAttribute('type', type);
        // toggle the eye slash icon
        this.classList.toggle('visibility_on'); */
        if ($(this).text() == "visibility_off") {
        $(this).text("visibility");
        $("#password").attr("type", "text");
        } else {
        $(this).text("visibility_off");
        $("#password").attr("type", "password");
        }
        
        });
        });
        </script>
        </head>
        
        <%@include file="head.jsp"%>
        
        <%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
        <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
        <%@taglib prefix="p" uri="http://java.sun.com/jsp/jstl/core"%>
        
        <div style="height: 90vh;">
        <form action="profileProcess" method="post"
        enctype="multipart/form-data">
        <div class="row" style="margin: 1px;">
        
        <div class="col-sm-1"></div>
        
        <div class="col-sm-10"
        style="box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2); transition: 0.3s;">
        
        <h1 align="center">Profile Here</h1>
        <hr>
        
        <div align="center">
        <%-- <img class="rounded-circle"
        src="<spring:url value="/images/abc.jpg"/>" width="150"
        height="150"> --%>
        
        <p:choose>
        <p:when test="${sessionScope.user.profileimage ne null}">
        
        <img class="img-circle"
        src="<spring:url value="/profileimage/${sessionScope.user.profileimage}"/>"
        height="150" width="170">
        </p:when>
        
        <p:otherwise>
        <img class="img-circle"
        src="<spring:url value="/images/abc.jpg"/>" width="170"
        height="150">
        </p:otherwise>
        </p:choose>
        
        </div>
        <br>
        <div class="col-md-2"></div>
        
        <div class="col-md-4">
        <br>
        <div class="form-group">
        <label for="name">Full Name:</label> <input type="text"
        class="form-control" id="name" value="${sessionScope.user.name}"
        placeholder="Enter Name" autocomplete="off" name="name" required="required">
        </div>
        <div class="form-group">
        <label for="price">Email Id:</label> <input type="email"
        class="form-control" id="email" value="${sessionScope.user.email}"
        placeholder="Enter Email" name="price" readonly="readonly">
        </div>
        </div>
        
        
        <div class="col-md-4">
        <br>
        <div class="form-group">
        <label for="quantity">Password</label>
        <div
        style="display: flex; align-items: center; border: 1px lightgray solid; border-radius: 5px;">
        <input type="password" class="form-control" style="border: 0;"
        id="password" name="pass" placeholder="Enter Password" required="required"
        value="${sessionScope.user.pass}"><span id="off"
        style="cursor: default; margin-right: 12px;"
        class="material-icons md-24">visibility_off</span>
        </div>
        </div>
        <div class="form-group">
        <label for="file">Upload Profile Image</label> <input type="file"
        class="form-control" id="customFile" name="imageprofile">
        </div>
        
        </div>
        
        
        <div class="form-inline">
        
        <div class="row"
        style="box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2); transition: 0.3s;">
        <div class="col-sm-3"></div>
        <div class="col-sm-6" align="center">
        <br>
        <button type="submit" class="btn btn-primary" style="width: 100%;">Update
        Profile</button>
        <br> <br> <br>
        </div>
        <div class="col-sm-2"></div>
        </div>
        </div>
        
        </div>
        
        </div>
        
        </form>
        <br>
        <%@include file="foot.jsp"%>
        </div>
    

pom.xml


<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ExpenseSpringProject</groupId>
<artifactId>ExpenseSpringProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>10</release>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.1</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.1.5.RELEASE</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.1.5.RELEASE</version>
</dependency>

<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.25</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>

<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.4</version>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>

</dependencies>

</project>

1 comment:

Unknown said...

Very nicely explain the contents individually.thank u so much sir.