Skip to content

Commit 08f3bd2

Browse files
committed
24/10/2017 at 11:53
1 parent bf56331 commit 08f3bd2

File tree

81 files changed

+2215
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+2215
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Manifest-Version: 1.0
2+
Class-Path:
3+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<%@ page language="java" contentType="text/html; charset=UTF-8"
2+
pageEncoding="UTF-8"%>
3+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
4+
<html>
5+
<head>
6+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
7+
<title>Insert title here</title>
8+
</head>
9+
<body>
10+
<%
11+
String message [] = (String [])request.getAttribute("myWelcomeMessage");
12+
String welcomeMessage = "";
13+
for(String str : message){
14+
welcomeMessage += str + " ";
15+
}
16+
out.print(welcomeMessage);
17+
%>
18+
</body>
19+
</html>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<%@ page language="java" contentType="text/html; charset=UTF-8"
2+
pageEncoding="UTF-8"%>
3+
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
4+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
5+
<html>
6+
<head>
7+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
8+
<title>Insert title here</title>
9+
</head>
10+
<body>
11+
<c:forEach var="messageItem" items="${myWelcomeMessage}">
12+
<c:out value="${messageItem}"></c:out>
13+
</c:forEach>
14+
</body>
15+
</html>

JavaSpringDemo/pom.xml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<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">
2+
<modelVersion>4.0.0</modelVersion>
3+
<groupId>JavaSpringDemo</groupId>
4+
<artifactId>JavaSpringDemo</artifactId>
5+
<version>0.0.1-SNAPSHOT</version>
6+
<packaging>war</packaging>
7+
8+
<dependencies>
9+
<dependency>
10+
<groupId>javax.servlet</groupId>
11+
<artifactId>javax.servlet-api</artifactId>
12+
<version>4.0.0</version>
13+
<scope>provided</scope>
14+
</dependency>
15+
<dependency>
16+
<groupId>javax.servlet</groupId>
17+
<artifactId>jstl</artifactId>
18+
<version>1.2</version>
19+
</dependency>
20+
</dependencies>
21+
22+
<build>
23+
<sourceDirectory>src</sourceDirectory>
24+
<plugins>
25+
<plugin>
26+
<artifactId>maven-compiler-plugin</artifactId>
27+
<version>3.6.1</version>
28+
<configuration>
29+
<source>1.8</source>
30+
<target>1.8</target>
31+
</configuration>
32+
</plugin>
33+
<plugin>
34+
<artifactId>maven-war-plugin</artifactId>
35+
<version>3.0.0</version>
36+
<configuration>
37+
<warSourceDirectory>WebContent</warSourceDirectory>
38+
</configuration>
39+
</plugin>
40+
</plugins>
41+
</build>
42+
</project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.java.spring.service.demo;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class WelcomeService {
7+
public List<String> getWelcomeMessage(String name) {
8+
List<String> myWelcomeMessage = new ArrayList<>();
9+
10+
myWelcomeMessage.add("Hello! ");
11+
myWelcomeMessage.add(name);
12+
myWelcomeMessage.add(", Welcome to the spring cours :-");
13+
14+
return myWelcomeMessage;
15+
}
16+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.java.spring.servlet.demo;
2+
3+
import java.io.IOException;
4+
5+
import javax.servlet.RequestDispatcher;
6+
import javax.servlet.ServletException;
7+
import javax.servlet.annotation.WebServlet;
8+
import javax.servlet.http.HttpServlet;
9+
import javax.servlet.http.HttpServletRequest;
10+
import javax.servlet.http.HttpServletResponse;
11+
12+
/**
13+
* Servlet implementation class WelcomeServlet
14+
*/
15+
@WebServlet("/WelcomeServlet")
16+
public class WelcomeServlet extends HttpServlet {
17+
private static final long serialVersionUID = 1L;
18+
19+
/**
20+
* @see HttpServlet#HttpServlet()
21+
*/
22+
public WelcomeServlet() {
23+
super();
24+
// TODO Auto-generated constructor stub
25+
}
26+
27+
/**
28+
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
29+
*/
30+
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
31+
//1. Create the data (model) and then add it to the request object
32+
String welcomeMessage [] = {"Hello!", "Welcome to the spring cours"};
33+
request.setAttribute("myWelcomeMessage", welcomeMessage);
34+
35+
//2. Retrieve request dispatcher
36+
RequestDispatcher requestDispatcher = request.getRequestDispatcher("welcome.jsp");
37+
38+
//3. Forward the request to the view
39+
requestDispatcher.forward(request, response);
40+
}
41+
42+
/**
43+
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
44+
*/
45+
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
46+
// TODO Auto-generated method stub
47+
doGet(request, response);
48+
}
49+
50+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package com.java.spring.servlet.demo;
2+
3+
import java.io.IOException;
4+
import java.util.List;
5+
6+
import javax.servlet.RequestDispatcher;
7+
import javax.servlet.ServletException;
8+
import javax.servlet.annotation.WebServlet;
9+
import javax.servlet.http.HttpServlet;
10+
import javax.servlet.http.HttpServletRequest;
11+
import javax.servlet.http.HttpServletResponse;
12+
13+
import com.java.spring.service.demo.WelcomeService;
14+
15+
/**
16+
* Servlet implementation class WelcomeServlet
17+
*/
18+
@WebServlet("/WelcomeServletNew")
19+
public class WelcomeServletNew extends HttpServlet {
20+
private static final long serialVersionUID = 1L;
21+
22+
/**
23+
* @see HttpServlet#HttpServlet()
24+
*/
25+
public WelcomeServletNew() {
26+
super();
27+
// TODO Auto-generated constructor stub
28+
}
29+
30+
/**
31+
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
32+
*/
33+
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
34+
//1. Create the data (model) and then add it to the request object
35+
WelcomeService welcomeService = new WelcomeService();
36+
List<String> welcomeMessage = welcomeService.getWelcomeMessage("jamal");
37+
request.setAttribute("myWelcomeMessage", welcomeMessage);
38+
39+
//2. Retrieve request dispatcher
40+
RequestDispatcher requestDispatcher = request.getRequestDispatcher("welcomeNew.jsp");
41+
42+
//3. Forward the request to the view
43+
requestDispatcher.forward(request, response);
44+
}
45+
46+
/**
47+
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
48+
*/
49+
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
50+
// TODO Auto-generated method stub
51+
doGet(request, response);
52+
}
53+
54+
}

springDemo/pom.xml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>com.jamal</groupId>
6+
<artifactId>springDemo</artifactId>
7+
<version>1.0-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<name>springDemo</name>
11+
<url>http://maven.apache.org</url>
12+
13+
<properties>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
16+
</properties>
17+
18+
<dependencies>
19+
<dependency>
20+
<groupId>junit</groupId>
21+
<artifactId>junit</artifactId>
22+
<version>4.12</version>
23+
<scope>test</scope>
24+
</dependency>
25+
<dependency>
26+
<groupId>org.springframework</groupId>
27+
<artifactId>spring-core</artifactId>
28+
<version>4.3.11.RELEASE</version>
29+
</dependency>
30+
<dependency>
31+
<groupId>org.springframework</groupId>
32+
<artifactId>spring-beans</artifactId>
33+
<version>4.3.11.RELEASE</version>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.springframework</groupId>
37+
<artifactId>spring-context</artifactId>
38+
<version>4.3.11.RELEASE</version>
39+
</dependency>
40+
</dependencies>
41+
42+
<build>
43+
<finalName>springMvcDemo2</finalName>
44+
<plugins>
45+
<plugin>
46+
<artifactId>maven-compiler-plugin</artifactId>
47+
<version>3.6.1</version>
48+
<configuration>
49+
<source>1.8</source>
50+
<target>1.8</target>
51+
</configuration>
52+
</plugin>
53+
</plugins>
54+
</build>
55+
</project>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.jamal.springDemo;
2+
3+
import org.springframework.context.ApplicationContext;
4+
import org.springframework.context.support.ClassPathXmlApplicationContext;
5+
6+
/**
7+
* Hello world!
8+
*
9+
*/
10+
public class AppAware
11+
{
12+
public static void main( String[] args ){
13+
//create the application context (container)
14+
//ApplicationContext ctx = new FileSystemXmlApplicationContext("bean.xml");
15+
ApplicationContext ctx = new ClassPathXmlApplicationContext("bean-aware.xml");
16+
17+
//close the application context (container)
18+
((ClassPathXmlApplicationContext)ctx).close();
19+
}
20+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.jamal.springDemo;
2+
3+
import org.springframework.context.ApplicationContext;
4+
import org.springframework.context.support.ClassPathXmlApplicationContext;
5+
6+
import com.jamal.springDemo.domain.OrganisationCB;
7+
8+
/**
9+
* Hello world!
10+
*
11+
*/
12+
public class AppCB
13+
{
14+
public static void main( String[] args ){
15+
//create the application context (container)
16+
//ApplicationContext ctx = new FileSystemXmlApplicationContext("bean.xml");
17+
ApplicationContext ctx = new ClassPathXmlApplicationContext("bean-cb.xml");
18+
19+
//create the beans
20+
OrganisationCB org = (OrganisationCB) ctx.getBean("myorg");
21+
22+
System.out.println(org);
23+
24+
//close the application context (container)
25+
((ClassPathXmlApplicationContext)ctx).close();
26+
}
27+
}

0 commit comments

Comments
 (0)