GithubHelp home page GithubHelp logo

webcontactsystem's Introduction

WebContactSystem

A simple demo of Web Contact System - my attempt to connect database in a dynamic webpage through Java servlet. See scottsun folder for details

System Design:

alt text

How it looks like

All pages are dynamic pages except Add Contact Page - [addContact.html]

Main page - shows all contacts:

alt text

Add Contact Page:

alt text

Edit Contact Page:

alt text

Step by Step how to set it up:

Step 1 - set up:

  1. MyEclipse 2014: IDE tool of your choice.. I have MyEclipse 2014 set up on my computer already
  2. Sublime Text: I use this to write addContact.html, ContactSystem.sql, and db.properties
  3. MySQL
  4. Tomcat
  5. JavaSE

Step 2 - create a table in the database and set up property file

SQL for your database, you can change the database name and information inside, but if you do that, you neeed to change your property file and Java code too.

ContactSystem.sql

create database webcontactsystem;

use webcontactsystem;

create table Contact (
	id int not null primary key auto_increment,
	firstName char(20) not null,
	lastName char(20) not null,
	gender char(1) not null,
	age tinyint not null,
	tel char(30),
	email char(30)
);

db.properties - save this file under /webapps/../WEB-INF/classes

driver=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3306/webcontactsystem?useSSL=true
user=root
password=123456

Step 3: Set up folder Tree

alt text

Step 3: You can start Coding now

You need to import the following libs:
beanutils
beanutils logging
mysql connector

My order of coding each file:

  1. Contact.java
  2. JDBCUtil.java
  3. BaseDao.java
  4. ContactDao.java
  5. ContactDaoImplements.java
  6. addContact.html
  7. web.xml
  8. AddContactServlet.java
  9. ListContactServlet.java
  10. DeleteContactServlet.java
  11. QueryContactServlet.java
  12. UpdateContactServlet.java

now you are done and you can start testing

What to be mindful about..

  1. database table field name to be consistant with your code.
  2. do not miss a space when generating html in the servlet, I made a mistake that missed a space here and took me so long to find out(crying face):
    html += "<form action=UpdateContactServlet?id=" + contact.getId() + "method=POST>";
    
    right before method=POST, it need a space, otherwise, it will not submit to UpdateContactServlet, correct coding:
    html += "<form action=UpdateContactServlet?id=" + contact.getId() + " method=POST>";
    
  3. Everything above can be done in JSP or Spring framework for better result, but here we are focusing on CRUD to the database from webpages.

webcontactsystem's People

Contributors

scottsun17 avatar

Stargazers

 avatar

Watchers

 avatar

webcontactsystem's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.