Front-end pass username and web url to back-end then back-end will return boolean value to indicate whether the user can access the coresponding website.
Front-end calls RESTful APIs implemented by back-end to add, update, delete users and roles;
RBAC Model
The relation between user and role is many to many, so as that between role and access;
Admin is a special type of role which has all web accesses and can manage users and other roles;
Admin create a set of roles with corresponding access permissions and assign part of them to a new-added user.
User gain accesses based on the roles he/she is assigned with.
Database Table Design
User Table:
id
name
create_time
update_time
Role Table:
id
type
create_time
update_time
Access Table:
id
name
url
create_time
update_time
User-Role Table:
id
user_id
role_id
create_time
update_time
Role-Access Tabe:
id
role_id
access_id
create_time
update_time
RESTful APIs(According to company’s policy, url and request method are not provided):
Both Servlet(print HTML) and JSP(embed Java in HTML: expression, scriptlet, declaration) can create web pages without the other.
In MVC pattern, JSP handles the presentation view, generate dynamic web pages, while Servlet focuses on the business logic.
Comparsion of JSP and Serlet when creating pages alone:
JSP
Servlet
HTML file with .jsp extension. Contains static HTML. JSP to generate HTML. Has built-in JSP objects
Java class file. Generate all HTML. More steps to access web objects.
Benefits of MVC
Minimize the HTML code in Servlet.
Minimize the business logic in JSP.
Interaction between Controller and Model
Define an object together with helper classes to fetch or modify data from the database as data model.
Pass the dataSource to DB model in the controller to perform database pooling injection.
Call method of DB model in controller to fetch or modify data from the database, avoid the direct interaction between controller and database. This achieves good code logic, make code easily maintained and ensure the safety of database.
Interaction between Controller and View
Servlet access the data from request.
Servlet can forward the data to JSP using Dispatcher.
Servlet can add data to request object.
JSP access the data through requestor JSTL(brief grammar). ${data}$
JSP can redirect to Servlet using response.sendRedirect(<thePageUrl>).
User can not see the change of url when using forward, but can see when using redirect.
JSTL uses Formatting Message labels and locale to achieve internationalization: fmt:setLocale, fmt:bundle, fmt:message
Resource Files(translated version of labels)
Achieve locale from user’s selection or pageContext.request.locale
1 2 3 4 5 6 7
<!-->JSP will append locale after the basename automatically.<--> <fmt:setLocalevalue="es_ES"/> <fmt:bundlebasename="com.tutorialspoint.Example"> <fmt:messagekey="count.one"/><br/> <fmt:messagekey="count.two"/><br/> <fmt:messagekey="count.three"/><br/> </fmt:bundle>
State Management
Session is stored in the server while Cookie is stored in user’s web browser.