@@ -0,0 +1,85 @@ | |||
*.db | |||
############################## | |||
## Java | |||
############################## | |||
.mtj.tmp/ | |||
*.class | |||
*.jar | |||
*.war | |||
*.ear | |||
*.nar | |||
hs_err_pid* | |||
############################## | |||
## Maven | |||
############################## | |||
target/ | |||
pom.xml.tag | |||
pom.xml.releaseBackup | |||
pom.xml.versionsBackup | |||
pom.xml.next | |||
pom.xml.bak | |||
release.properties | |||
dependency-reduced-pom.xml | |||
buildNumber.properties | |||
.mvn/timing.properties | |||
.mvn/wrapper/maven-wrapper.jar | |||
############################## | |||
## Gradle | |||
############################## | |||
bin/ | |||
build/ | |||
.gradle | |||
.gradletasknamecache | |||
gradle-app.setting | |||
!gradle-wrapper.jar | |||
############################## | |||
## IntelliJ | |||
############################## | |||
out/ | |||
.idea/ | |||
.idea_modules/ | |||
*.iml | |||
*.ipr | |||
*.iws | |||
############################## | |||
## Eclipse | |||
############################## | |||
.settings/ | |||
bin/ | |||
tmp/ | |||
.metadata | |||
.classpath | |||
.project | |||
*.tmp | |||
*.bak | |||
*.swp | |||
*~.nib | |||
local.properties | |||
.loadpath | |||
.factorypath | |||
############################## | |||
## NetBeans | |||
############################## | |||
nbproject/private/ | |||
build/ | |||
nbbuild/ | |||
dist/ | |||
nbdist/ | |||
nbactions.xml | |||
nb-configuration.xml | |||
############################## | |||
## Visual Studio Code | |||
############################## | |||
.vscode/ | |||
.code-workspace | |||
############################## | |||
## OS X | |||
############################## | |||
.DS_Store |
@@ -0,0 +1,55 @@ | |||
<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/maven-v4_0_0.xsd"> | |||
<modelVersion>4.0.0</modelVersion> | |||
<groupId>cc.javastudio</groupId> | |||
<artifactId>simple-servlet-webapp</artifactId> | |||
<packaging>war</packaging> | |||
<version>1.0-SNAPSHOT</version> | |||
<properties> | |||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |||
<maven.compiler.source>11</maven.compiler.source> | |||
<maven.compiler.target>11</maven.compiler.target> | |||
</properties> | |||
<dependencies> | |||
<dependency> | |||
<groupId>org.springframework</groupId> | |||
<artifactId>spring-webmvc</artifactId> | |||
<version>5.3.6</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>javax.servlet</groupId> | |||
<artifactId>javax.servlet-api</artifactId> | |||
<version>4.0.1</version> | |||
</dependency> | |||
<dependency> | |||
<groupId>org.junit.jupiter</groupId> | |||
<artifactId>junit-jupiter</artifactId> | |||
<version>5.7.1</version> | |||
<scope>test</scope> | |||
</dependency> | |||
</dependencies> | |||
<build> | |||
<finalName>simple-servlet-webapp</finalName> | |||
<plugins> | |||
<plugin> | |||
<artifactId>maven-war-plugin</artifactId> | |||
<configuration> | |||
<attachClasses>true</attachClasses> | |||
<webResources> | |||
<resource> | |||
<directory>src/main/webapp</directory> | |||
<filtering>true</filtering> | |||
</resource> | |||
</webResources> | |||
</configuration> | |||
</plugin> | |||
</plugins> | |||
</build> | |||
</project> |
@@ -0,0 +1,21 @@ | |||
package cc.javastudio; | |||
import org.springframework.stereotype.Controller; | |||
import org.springframework.ui.Model; | |||
import org.springframework.web.bind.annotation.GetMapping; | |||
import org.springframework.web.bind.annotation.RequestMapping; | |||
@Controller | |||
@RequestMapping("/") | |||
public class IndexController { | |||
@GetMapping | |||
public String printHello(Model model) { | |||
model.addAttribute("title", "Home Page"); | |||
model.addAttribute("message", "Enjoy your day!"); | |||
model.addAttribute("date", new java.util.Date()); | |||
return "index"; | |||
} | |||
} |
@@ -0,0 +1,23 @@ | |||
package cc.javastudio.config; | |||
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; | |||
public class ApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { | |||
@Override | |||
protected Class<?>[] getRootConfigClasses() { | |||
return null; | |||
} | |||
@Override | |||
protected Class<?>[] getServletConfigClasses() { | |||
return new Class[] {WebConfig.class}; | |||
} | |||
@Override | |||
protected String[] getServletMappings() { | |||
return new String[] {"/"}; | |||
} | |||
} |
@@ -0,0 +1,30 @@ | |||
package cc.javastudio.config; | |||
import org.springframework.context.annotation.Bean; | |||
import org.springframework.context.annotation.ComponentScan; | |||
import org.springframework.context.annotation.Configuration; | |||
import org.springframework.web.servlet.ViewResolver; | |||
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer; | |||
import org.springframework.web.servlet.config.annotation.EnableWebMvc; | |||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | |||
import org.springframework.web.servlet.view.InternalResourceViewResolver; | |||
@Configuration | |||
@EnableWebMvc | |||
@ComponentScan("cc.javastudio") | |||
public class WebConfig implements WebMvcConfigurer { | |||
@Bean | |||
public ViewResolver initViewResolver() { | |||
InternalResourceViewResolver resolver = new InternalResourceViewResolver(); | |||
resolver.setPrefix("/WEB-INF/view/"); | |||
resolver.setSuffix(".jsp"); | |||
return resolver; | |||
} | |||
@Override | |||
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) { | |||
configurer.enable(); | |||
} | |||
} |
@@ -0,0 +1,13 @@ | |||
<%@ page contentType="text/html; charset=UTF-8" %> | |||
<!DOCTYPE html> | |||
<html lang="en"> | |||
<head> | |||
<meta charset="UTF-8"> | |||
<title>Title</title> | |||
</head> | |||
<body> | |||
<h1>${title}</h1> | |||
<p>${message}</p> | |||
<p>page generated at: ${date}</p> | |||
</body> | |||
</html> |