zoukankan      html  css  js  c++  java
  • Servlet JDBC Example

      

    Develop a web application that should have following features.

    1. User can register and then login to the application.
    2. The users information should be maintained in database.
    3. Use standard logging framework log4j.
    4. The application should support session management, no JSPs should be visible without session. Users can logout anytime from the application.
    5. We should not show application and server details to user incase of any exception in application or other common errors like 404.

      Once we have our basic application ready, we can move on to add other features.

      Design Decisions

      1. Since login page is the entry point of application, we will have a simple login.html where user can enter their credentials; email and password. We can’t rely on javascript validations, so we will do server side validation and incase of missing information we will redirect user to login page with error details.
      2. We will have a register.html from where user can register to our application, we will provide it’s link in the login page for new user. User should provide email, password, name and country details for registration.

        If any information is missing, user will remain on same page with error message. If registration is successful, user will be forwarded to the login page with registration success information and they can use email and password to login.

      3. We will use MySql database for persisting user information. We will create a new database, user and Users table for our application. Since our application totally depends on Database Connection, we will create a servlet context listener to initialize the database connection and set it as context attribute for other servlets.

        We will keep DB configuration details configurable through deployment descriptor. We will also add MySql Java Connector jar to the application libraries.

      4. Since we want to use log4j and configure it properly before usage, we will utilize servlet context listener to configure log4j and keep the log4j configuration XML file location in web.xml init parameters. We will write our application logs in a separate log file dbexample.log for easier debugging.
      5. Incase of any exceptions like “Database Connection Error” or 404 errors, we want to present a useful page to user. We will utilize servlet exception handling and write our own Exception Handler servlet and configure it in deployment descriptor.
      6. Once the user logins successfully, we will create a session for the user and forward them to home.jsp where we will show basic information of the user. We will have a model class User that will store the user data into session. User home page also provide logout button that will invalidate the session and forward them to login page.
      7. We need to make sure all the JSPs and other resources are accessible only when user has a valid session, rather than keeping session validation login in all the resources, we will create a Servlet Filter for session validation and configure it in deployment descriptor.
      8. We will use Servlet 3.0 features for servlet configuration, listeners and filters rather than keeping all of these in deployment descriptor. We will use Eclipse for development and Tomcat 7 for deployment.
    宛如智障,暗藏锋芒
  • 相关阅读:
    6-51单片机ESP8266学习-AT指令(8266TCP服务器--做自己的AndroidTCP客户端发信息给单片机控制小灯的亮灭)
    5-51单片机ESP8266学习-AT指令(8266TCP服务器--用手机TCP调试助手发信息给单片机控制小灯的亮灭)
    4-51单片机ESP8266学习-AT指令(测试TCP服务器--使用串口调试助手--不连接路由器)
    3-51单片机ESP8266学习-AT指令(学会刷固件)
    多线程之:synchonized锁实现的原理<一>
    多线程之:volatile变量的一次写操作的过程
    Spring 事务管理高级应用难点剖析: 第 3 部分
    Spring 事务管理高级应用难点剖析: 第 2 部分
    Spring 事务管理高级应用难点剖析: 第 1 部分
    多线程之:并发编程面临的挑战
  • 原文地址:https://www.cnblogs.com/zienzir/p/9044301.html
Copyright © 2011-2022 走看看