Skip to content

Commit ef4a914

Browse files
committed
lab05 add spring mvc jdbc jsp and h2 database.
1 parent bbea189 commit ef4a914

17 files changed

Lines changed: 503 additions & 98 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Course App (spring mvc)
2+
3+
## Assignment:
4+
5+
Spring Core, Spring MVC, REST, Security, Validation, Exception, Logging, JWT
6+
7+
## Develop:
8+
9+
User Registration & Login with CAPTCHA (Completely Automated Public Turing test to tell Computers and Human Apart)and one super admin
10+
11+
## Tech stack
12+
13+
1. [x] Spring MVC
14+
2. [ ] Spring Security
15+
3. [x] Spring JDBC
16+
4. [x] JSP/EL/JSTL
17+
5. [x] Bootstrap 4.3
18+
6. [x] Tomcat
19+
7. [x] H2 In-Memory Database
20+
21+
## Description:
22+
23+
1. Create User Registration page with captcha.
24+
2. Registered user details must be save to H2 in-memory database
25+
3. Create login page with captcha
26+
4. Captcha should have a reload button to re-send request to regenerate the captcha
27+
5. Write server side code for generating captcha image and sending it back with response.
28+
6. Code to verify whether the captcha string entered by user and stored in the session matches or not.
29+
30+
## Acitivity
31+
32+
1. [x] Create a Maven project
33+
2. [x] Use POM.xml to manage dependencies
34+
3. [x] Deployment Descriptor is created and configured to open default page of the spring mvc applicaton
35+
4. [x] Dispatcher Servlet is created and configured as per requirements
36+
5. [x] Controllers are created in repsectve package (com.something.controller)
37+
6. [?] POJO classes are created where required in respectve package (com.something.pojo)
38+
7. [x] Entty classes are created where required in respectve package (com.something.entty) for different groups of users
39+
8. [x] Service classes are created where required in respectve package (com.something.service)
40+
9. [x] DAO classes are created where required in respectve package (com.something.dao)
41+
10. [ ] View is created for user registraton
42+
11. [ ] View is created for user login
43+
12. [ ] View is created for account update
44+
13. [ ] If the user is not logged in, account update page is redirectng the user to login page; with line saying - login to update your account
45+
14. [ ] If the user is logged in, he/she can logout to come out of the secure session
46+
15. [ ] Admin (Page with dummy message about admin) page is visible and accessible only to the logged-in user who is super-admin
47+
16. [ ] Spring Security is used to implement user roles (guest user, logged-in user, super user)
48+
17. [ ] CAPTCHA image is being created by class in utl package (com.something.utl) and sent with response to view
49+
18. [ ] Have used Spring logging to dump the logs
50+
19. [ ] Have used Spring Validatons for validatng the user registraton informaton in respectve package (com.something.validaton)
51+
20. [ ] Have used Spring Exceptons to manage exceptons in respectve package (com.something.excepton)
52+
21. [ ] Any extra other than documented
53+
54+
## References
55+
56+
1. https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#mvc

lab05_spring5mvc_sec_jdbc/course-app/.classpath

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,26 @@
88
</classpathentry>
99
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
1010
<attributes>
11-
<attribute name="optional" value="true"/>
12-
<attribute name="maven.pomderived" value="true"/>
1311
<attribute name="test" value="true"/>
14-
</attributes>
15-
</classpathentry>
16-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
17-
<attributes>
12+
<attribute name="optional" value="true"/>
1813
<attribute name="maven.pomderived" value="true"/>
1914
</attributes>
2015
</classpathentry>
16+
<classpathentry kind="src" path="src/main/resouces"/>
2117
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
2218
<attributes>
2319
<attribute name="maven.pomderived" value="true"/>
2420
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
2521
</attributes>
2622
</classpathentry>
27-
<classpathentry kind="src" path="target/generated-sources/annotations">
23+
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v9.0">
2824
<attributes>
29-
<attribute name="optional" value="true"/>
30-
<attribute name="maven.pomderived" value="true"/>
31-
<attribute name="ignore_optional_problems" value="true"/>
32-
<attribute name="m2e-apt" value="true"/>
25+
<attribute name="owner.project.facets" value="jst.web"/>
3326
</attributes>
3427
</classpathentry>
35-
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
28+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
3629
<attributes>
37-
<attribute name="optional" value="true"/>
3830
<attribute name="maven.pomderived" value="true"/>
39-
<attribute name="ignore_optional_problems" value="true"/>
40-
<attribute name="m2e-apt" value="true"/>
41-
<attribute name="test" value="true"/>
4231
</attributes>
4332
</classpathentry>
4433
<classpathentry kind="output" path="target/classes"/>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# EditorConfig is awesome: http://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
# Unix-style newlines with a newline ending every file
7+
[*]
8+
end_of_line = lf
9+
insert_final_newline = true
10+
11+
# Matches multiple files with brace expansion notation
12+
# Set default charset
13+
[*.{java,xml,properties,sql}]
14+
charset = utf-8
15+
16+
# Indentation override for all JS under lib directory
17+
[*.{java,xml,properties,sql}]
18+
indent_style = space
19+
indent_size = 4
20+
21+
# Indentation for bash file
22+
[*.{sh,css,html}]
23+
indent_style = space
24+
indent_size = 2

lab05_spring5mvc_sec_jdbc/course-app/.project

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
</arguments>
1717
</buildCommand>
1818
<buildCommand>
19-
<name>org.eclipse.m2e.core.maven2Builder</name>
19+
<name>org.eclipse.wst.validation.validationbuilder</name>
2020
<arguments>
2121
</arguments>
2222
</buildCommand>
2323
<buildCommand>
24-
<name>org.eclipse.wst.validation.validationbuilder</name>
24+
<name>org.eclipse.m2e.core.maven2Builder</name>
2525
<arguments>
2626
</arguments>
2727
</buildCommand>
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1+
## Setup
2+
3+
1. Deploy war package on tomcat 9 server
4+
2. Visit http://localhost:8080/course-app/
15

26
## References
37

4-
1. https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#mvc
8+
1. https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#mvc
9+
2. https://howtodoinjava.com/spring5/webmvc/spring-dispatcherservlet-tutorial/
10+
3. https://stackoverflow.com/questions/41577234/why-does-spring-mvc-respond-with-a-404-and-report-no-mapping-found-for-http-req
Lines changed: 129 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,137 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5-
<modelVersion>4.0.0</modelVersion>
3+
<project xmlns="http://maven.apache.org/POM/4.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
6+
<modelVersion>4.0.0</modelVersion>
67

7-
<groupId>me.cyper.fsd.lab05</groupId>
8-
<artifactId>course-app</artifactId>
9-
<version>1.0-SNAPSHOT</version>
10-
<packaging>war</packaging>
8+
<groupId>me.cyper.fsd.lab05</groupId>
9+
<artifactId>course-app</artifactId>
10+
<version>1.0-SNAPSHOT</version>
11+
<packaging>war</packaging>
1112

12-
<name>course-app Maven Webapp</name>
13-
<!-- FIXME change it to the project's website -->
14-
<url>http://www.example.com</url>
13+
<name>course-app Maven Webapp</name>
14+
<!-- FIXME change it to the project's website -->
15+
<url>http://www.example.com</url>
1516

16-
<properties>
17-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
18-
<maven.compiler.source>1.8</maven.compiler.source>
19-
<maven.compiler.target>1.8</maven.compiler.target>
20-
</properties>
17+
<properties>
18+
<failOnMissingWebXml>false</failOnMissingWebXml>
19+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
20+
<maven.compiler.source>1.8</maven.compiler.source>
21+
<maven.compiler.target>1.8</maven.compiler.target>
22+
<jdk.version>1.8</jdk.version>
23+
<spring.version>5.1.8.RELEASE</spring.version>
24+
<junit.version>4.11</junit.version>
25+
<jstl.version>1.2.1</jstl.version>
26+
<tld.version>1.1.2</tld.version>
27+
<servlets.version>3.1.0</servlets.version>
28+
<jsp.version>2.3.1</jsp.version>
29+
</properties>
2130

22-
<dependencies>
23-
<dependency>
24-
<groupId>junit</groupId>
25-
<artifactId>junit</artifactId>
26-
<version>4.11</version>
27-
<scope>test</scope>
28-
</dependency>
29-
</dependencies>
31+
<dependencies>
32+
<!-- Unit Test -->
33+
<dependency>
34+
<groupId>junit</groupId>
35+
<artifactId>junit</artifactId>
36+
<version>${junit.version}</version>
37+
<scope>test</scope>
38+
</dependency>
3039

31-
<build>
32-
<finalName>course-app</finalName>
33-
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
34-
<plugins>
35-
<plugin>
36-
<artifactId>maven-clean-plugin</artifactId>
37-
<version>3.1.0</version>
38-
</plugin>
39-
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
40-
<plugin>
41-
<artifactId>maven-resources-plugin</artifactId>
42-
<version>3.0.2</version>
43-
</plugin>
44-
<plugin>
45-
<artifactId>maven-compiler-plugin</artifactId>
46-
<version>3.8.0</version>
47-
</plugin>
48-
<plugin>
49-
<artifactId>maven-surefire-plugin</artifactId>
50-
<version>2.22.1</version>
51-
</plugin>
52-
<plugin>
53-
<artifactId>maven-war-plugin</artifactId>
54-
<version>3.2.2</version>
55-
</plugin>
56-
<plugin>
57-
<artifactId>maven-install-plugin</artifactId>
58-
<version>2.5.2</version>
59-
</plugin>
60-
<plugin>
61-
<artifactId>maven-deploy-plugin</artifactId>
62-
<version>2.8.2</version>
63-
</plugin>
64-
</plugins>
65-
</pluginManagement>
66-
</build>
40+
<!-- Apache Commons -->
41+
<dependency>
42+
<groupId>org.apache.commons</groupId>
43+
<artifactId>commons-lang3</artifactId>
44+
<version>3.7</version>
45+
</dependency>
46+
47+
48+
<!-- Spring MVC Dependency -->
49+
<dependency>
50+
<groupId>org.springframework</groupId>
51+
<artifactId>spring-webmvc</artifactId>
52+
<version>${spring.version}</version>
53+
</dependency>
54+
55+
<!-- Spring JDBC Dependency -->
56+
<dependency>
57+
<groupId>org.springframework</groupId>
58+
<artifactId>spring-jdbc</artifactId>
59+
<version>${spring.version}</version>
60+
</dependency>
61+
62+
<!-- JSTL Dependency -->
63+
<dependency>
64+
<groupId>javax.servlet.jsp.jstl</groupId>
65+
<artifactId>javax.servlet.jsp.jstl-api</artifactId>
66+
<version>${jstl.version}</version>
67+
</dependency>
68+
69+
<dependency>
70+
<groupId>taglibs</groupId>
71+
<artifactId>standard</artifactId>
72+
<version>${tld.version}</version>
73+
</dependency>
74+
75+
<!-- Servlet Dependency -->
76+
<dependency>
77+
<groupId>javax.servlet</groupId>
78+
<artifactId>javax.servlet-api</artifactId>
79+
<version>${servlets.version}</version>
80+
<scope>provided</scope>
81+
</dependency>
82+
83+
<!-- JSP Dependency -->
84+
<dependency>
85+
<groupId>javax.servlet.jsp</groupId>
86+
<artifactId>javax.servlet.jsp-api</artifactId>
87+
<version>${jsp.version}</version>
88+
<scope>provided</scope>
89+
</dependency>
90+
91+
<!-- https://mvnrepository.com/artifact/com.h2database/h2 -->
92+
<dependency>
93+
<groupId>com.h2database</groupId>
94+
<artifactId>h2</artifactId>
95+
<version>1.4.199</version>
96+
</dependency>
97+
98+
</dependencies>
99+
100+
<build>
101+
<finalName>course-app</finalName>
102+
<pluginManagement><!-- lock down plugins versions to avoid using
103+
Maven defaults (may be moved to parent pom) -->
104+
<plugins>
105+
<plugin>
106+
<artifactId>maven-clean-plugin</artifactId>
107+
<version>3.1.0</version>
108+
</plugin>
109+
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
110+
<plugin>
111+
<artifactId>maven-resources-plugin</artifactId>
112+
<version>3.0.2</version>
113+
</plugin>
114+
<plugin>
115+
<artifactId>maven-compiler-plugin</artifactId>
116+
<version>3.8.0</version>
117+
</plugin>
118+
<plugin>
119+
<artifactId>maven-surefire-plugin</artifactId>
120+
<version>2.22.1</version>
121+
</plugin>
122+
<plugin>
123+
<artifactId>maven-war-plugin</artifactId>
124+
<version>3.2.2</version>
125+
</plugin>
126+
<plugin>
127+
<artifactId>maven-install-plugin</artifactId>
128+
<version>2.5.2</version>
129+
</plugin>
130+
<plugin>
131+
<artifactId>maven-deploy-plugin</artifactId>
132+
<version>2.8.2</version>
133+
</plugin>
134+
</plugins>
135+
</pluginManagement>
136+
</build>
67137
</project>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package me.cyper.fsd.lab05.controller;
2+
3+
import java.util.List;
4+
import java.util.Locale;
5+
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.stereotype.Controller;
8+
import org.springframework.ui.Model;
9+
import org.springframework.web.bind.annotation.GetMapping;
10+
import org.springframework.web.servlet.ModelAndView;
11+
12+
import me.cyper.fsd.lab05.entity.User;
13+
import me.cyper.fsd.lab05.service.UserService;
14+
15+
@Controller
16+
public class HomeController {
17+
18+
@Autowired
19+
private UserService userService;
20+
21+
@GetMapping("/")
22+
public ModelAndView homeInit(Locale locale, Model model) {
23+
24+
ModelAndView mv = new ModelAndView("home");
25+
26+
List<User> users = userService.findAllUsers();
27+
mv.addObject("users", users);
28+
29+
return mv;
30+
}
31+
}

0 commit comments

Comments
 (0)