From 445fee41b3925c4bd8272068e432263ec06d378c Mon Sep 17 00:00:00 2001 From: Joel Juarez Date: Sun, 30 Dec 2018 23:38:13 +0100 Subject: [PATCH 1/5] java web application without web.xml - servlets 3.0 --- javax-servlets-3/.gitignore | 6 +++ javax-servlets-3/Dockerfile | 2 + javax-servlets-3/README.md | 9 ++++ javax-servlets-3/pom.xml | 51 +++++++++++++++++++ .../servlets3/spring/AppInitializer.java | 27 ++++++++++ .../servlets3/spring/config/AppConfig.java | 11 ++++ .../controllers/UppercaseController.java | 17 +++++++ .../web/filters/EmptyParamFilter.java | 44 ++++++++++++++++ .../servlets3/web/listeners/AppListener.java | 21 ++++++++ .../web/listeners/RequestListener.java | 24 +++++++++ .../web/servlets/CounterServlet.java | 27 ++++++++++ .../web/servlets/UppercaseServlet.java | 26 ++++++++++ 12 files changed, 265 insertions(+) create mode 100644 javax-servlets-3/.gitignore create mode 100644 javax-servlets-3/Dockerfile create mode 100644 javax-servlets-3/README.md create mode 100644 javax-servlets-3/pom.xml create mode 100644 javax-servlets-3/src/main/java/com/baeldung/servlets3/spring/AppInitializer.java create mode 100644 javax-servlets-3/src/main/java/com/baeldung/servlets3/spring/config/AppConfig.java create mode 100644 javax-servlets-3/src/main/java/com/baeldung/servlets3/spring/controllers/UppercaseController.java create mode 100644 javax-servlets-3/src/main/java/com/baeldung/servlets3/web/filters/EmptyParamFilter.java create mode 100644 javax-servlets-3/src/main/java/com/baeldung/servlets3/web/listeners/AppListener.java create mode 100644 javax-servlets-3/src/main/java/com/baeldung/servlets3/web/listeners/RequestListener.java create mode 100644 javax-servlets-3/src/main/java/com/baeldung/servlets3/web/servlets/CounterServlet.java create mode 100644 javax-servlets-3/src/main/java/com/baeldung/servlets3/web/servlets/UppercaseServlet.java diff --git a/javax-servlets-3/.gitignore b/javax-servlets-3/.gitignore new file mode 100644 index 000000000000..dfbd0632874e --- /dev/null +++ b/javax-servlets-3/.gitignore @@ -0,0 +1,6 @@ +# Created by .ignore support plugin (hsz.mobi) +.idea +classes +target +*.iml +out \ No newline at end of file diff --git a/javax-servlets-3/Dockerfile b/javax-servlets-3/Dockerfile new file mode 100644 index 000000000000..97cc1897dd00 --- /dev/null +++ b/javax-servlets-3/Dockerfile @@ -0,0 +1,2 @@ +FROM tomcat +ADD ./target/javax-servlets-3-1.0-SNAPSHOT.war /usr/local/tomcat/webapps/ \ No newline at end of file diff --git a/javax-servlets-3/README.md b/javax-servlets-3/README.md new file mode 100644 index 000000000000..ff310b5928cb --- /dev/null +++ b/javax-servlets-3/README.md @@ -0,0 +1,9 @@ +## Build with maven: +mvn package + +## Run with Tomcat on Docker container: +docker build --tag my-tomcat . +docker run -it --rm -p 8080:8080 my-tomcat + +### Relevant Articles: +- [Java Web Application Without Web.xml] diff --git a/javax-servlets-3/pom.xml b/javax-servlets-3/pom.xml new file mode 100644 index 000000000000..2b4fc37fc4d2 --- /dev/null +++ b/javax-servlets-3/pom.xml @@ -0,0 +1,51 @@ + + + 4.0.0 + javax-servlets-3 + 1.0-SNAPSHOT + javax-servlets-3 + war + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + + + + javax.servlet + javax.servlet-api + ${javax.servlet-api.version} + + + org.springframework + spring-webmvc + ${spring.version} + + + + 4.0.1 + 5.1.3.RELEASE + + + + + org.apache.maven.plugins + maven-war-plugin + 3.1.0 + + + default-war + prepare-package + + false + + + + + + + diff --git a/javax-servlets-3/src/main/java/com/baeldung/servlets3/spring/AppInitializer.java b/javax-servlets-3/src/main/java/com/baeldung/servlets3/spring/AppInitializer.java new file mode 100644 index 000000000000..837d439cf409 --- /dev/null +++ b/javax-servlets-3/src/main/java/com/baeldung/servlets3/spring/AppInitializer.java @@ -0,0 +1,27 @@ +package com.baeldung.servlets3.spring; + +import com.baeldung.servlets3.spring.config.AppConfig; +import org.springframework.web.WebApplicationInitializer; +import org.springframework.web.context.ContextLoaderListener; +import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; +import org.springframework.web.servlet.DispatcherServlet; + +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.ServletRegistration; + +public class AppInitializer implements WebApplicationInitializer { + @Override + public void onStartup(ServletContext servletContext) throws ServletException { + AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); + context.register(AppConfig.class); + + servletContext.addListener(new ContextLoaderListener(context)); + + ServletRegistration.Dynamic dispatcher = servletContext.addServlet("spring-dispatcher", + new DispatcherServlet(context)); + + dispatcher.setLoadOnStartup(1); + dispatcher.addMapping("/spring/*"); + } +} diff --git a/javax-servlets-3/src/main/java/com/baeldung/servlets3/spring/config/AppConfig.java b/javax-servlets-3/src/main/java/com/baeldung/servlets3/spring/config/AppConfig.java new file mode 100644 index 000000000000..0088bad77099 --- /dev/null +++ b/javax-servlets-3/src/main/java/com/baeldung/servlets3/spring/config/AppConfig.java @@ -0,0 +1,11 @@ +package com.baeldung.servlets3.spring.config; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; + +@Configuration +@EnableWebMvc +@ComponentScan("com.baeldung.servlets3.spring") +public class AppConfig { +} diff --git a/javax-servlets-3/src/main/java/com/baeldung/servlets3/spring/controllers/UppercaseController.java b/javax-servlets-3/src/main/java/com/baeldung/servlets3/spring/controllers/UppercaseController.java new file mode 100644 index 000000000000..74585e6b5e1d --- /dev/null +++ b/javax-servlets-3/src/main/java/com/baeldung/servlets3/spring/controllers/UppercaseController.java @@ -0,0 +1,17 @@ +package com.baeldung.servlets3.spring.controllers; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/uppercase") +public class UppercaseController { + + @GetMapping(produces = "text/html") + public String getUppercase(@RequestParam(required = false)String param) { + String response = param != null ? param.toUpperCase() : "Missing param"; + return "From Spring: " + response; + } +} diff --git a/javax-servlets-3/src/main/java/com/baeldung/servlets3/web/filters/EmptyParamFilter.java b/javax-servlets-3/src/main/java/com/baeldung/servlets3/web/filters/EmptyParamFilter.java new file mode 100644 index 000000000000..2c9f603d2c32 --- /dev/null +++ b/javax-servlets-3/src/main/java/com/baeldung/servlets3/web/filters/EmptyParamFilter.java @@ -0,0 +1,44 @@ +package com.baeldung.servlets3.web.filters; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.annotation.WebFilter; +import java.io.IOException; +import java.io.PrintWriter; + +@WebFilter(servletNames = { "uppercaseServlet" }, filterName = "emptyParamFilter") +public class EmptyParamFilter implements Filter { + + @Override + public void init(FilterConfig filterConfig) throws ServletException { + } + + @Override + public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, + FilterChain filterChain) throws IOException, ServletException { + String inputString = servletRequest.getParameter("input"); + + if (inputString == null || inputString.isEmpty()) { + response(servletResponse); + } else { + filterChain.doFilter(servletRequest, servletResponse); + } + } + + private void response(ServletResponse response) throws IOException { + response.setContentType("text/html"); + + PrintWriter out = response.getWriter(); + + out.println("Missing input parameter"); + } + + @Override + public void destroy() { + } + +} diff --git a/javax-servlets-3/src/main/java/com/baeldung/servlets3/web/listeners/AppListener.java b/javax-servlets-3/src/main/java/com/baeldung/servlets3/web/listeners/AppListener.java new file mode 100644 index 000000000000..d61af65c31d9 --- /dev/null +++ b/javax-servlets-3/src/main/java/com/baeldung/servlets3/web/listeners/AppListener.java @@ -0,0 +1,21 @@ +package com.baeldung.servlets3.web.listeners; + +import javax.servlet.ServletContext; +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; +import javax.servlet.annotation.WebListener; + +@WebListener +public class AppListener implements ServletContextListener { + + @Override + public void contextInitialized(ServletContextEvent event) { + ServletContext context = event.getServletContext(); + context.setAttribute("counter", 0); + } + + @Override + public void contextDestroyed(ServletContextEvent event) { + + } +} diff --git a/javax-servlets-3/src/main/java/com/baeldung/servlets3/web/listeners/RequestListener.java b/javax-servlets-3/src/main/java/com/baeldung/servlets3/web/listeners/RequestListener.java new file mode 100644 index 000000000000..aeebf482fb8e --- /dev/null +++ b/javax-servlets-3/src/main/java/com/baeldung/servlets3/web/listeners/RequestListener.java @@ -0,0 +1,24 @@ +package com.baeldung.servlets3.web.listeners; + +import javax.servlet.ServletContext; +import javax.servlet.ServletRequestEvent; +import javax.servlet.ServletRequestListener; +import javax.servlet.annotation.WebListener; +import javax.servlet.http.HttpServletRequest; + +@WebListener +public class RequestListener implements ServletRequestListener { + + @Override + public void requestInitialized(ServletRequestEvent event) { + } + + @Override + public void requestDestroyed(ServletRequestEvent event) { + HttpServletRequest request = (HttpServletRequest)event.getServletRequest(); + if (!request.getServletPath().equals("/counter")) { + ServletContext context = event.getServletContext(); + context.setAttribute("counter", (int)context.getAttribute("counter") + 1); + } + } +} diff --git a/javax-servlets-3/src/main/java/com/baeldung/servlets3/web/servlets/CounterServlet.java b/javax-servlets-3/src/main/java/com/baeldung/servlets3/web/servlets/CounterServlet.java new file mode 100644 index 000000000000..4bb92bbf7729 --- /dev/null +++ b/javax-servlets-3/src/main/java/com/baeldung/servlets3/web/servlets/CounterServlet.java @@ -0,0 +1,27 @@ +package com.baeldung.servlets3.web.servlets; + +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; + +@WebServlet(urlPatterns = "/counter", name = "counterServlet") +public class CounterServlet extends HttpServlet { + + public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { + doGet(request, response); + } + + public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { + response.setContentType("text/html"); + + PrintWriter out = response.getWriter(); + + int count = (int)request.getServletContext().getAttribute("counter"); + + out.println("Request counter: " + count); + } + +} diff --git a/javax-servlets-3/src/main/java/com/baeldung/servlets3/web/servlets/UppercaseServlet.java b/javax-servlets-3/src/main/java/com/baeldung/servlets3/web/servlets/UppercaseServlet.java new file mode 100644 index 000000000000..9b948cd99429 --- /dev/null +++ b/javax-servlets-3/src/main/java/com/baeldung/servlets3/web/servlets/UppercaseServlet.java @@ -0,0 +1,26 @@ +package com.baeldung.servlets3.web.servlets; + +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; + +@WebServlet(urlPatterns = "/uppercase", name = "uppercaseServlet") +public class UppercaseServlet extends HttpServlet { + + public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { + doGet(request, response); + } + + public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { + String inputString = request.getParameter("input").toUpperCase(); + + response.setContentType("text/html"); + + PrintWriter out = response.getWriter(); + + out.println(inputString); + } +} From fc88c99537ce2f4bb3b08b9e3da1da82e5bc9ee6 Mon Sep 17 00:00:00 2001 From: Joel Juarez Date: Fri, 15 Feb 2019 22:53:52 +0100 Subject: [PATCH 2/5] fixed README file changed filter to match url pattern --- javax-servlets-3/Dockerfile | 2 +- javax-servlets-3/README.md | 3 ++- javax-servlets-3/pom.xml | 1 + .../servlets3/web/filters/EmptyParamFilter.java | 17 ++++------------- 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/javax-servlets-3/Dockerfile b/javax-servlets-3/Dockerfile index 97cc1897dd00..27d1450acbbf 100644 --- a/javax-servlets-3/Dockerfile +++ b/javax-servlets-3/Dockerfile @@ -1,2 +1,2 @@ FROM tomcat -ADD ./target/javax-servlets-3-1.0-SNAPSHOT.war /usr/local/tomcat/webapps/ \ No newline at end of file +ADD ./target/uppercasing-app.war /usr/local/tomcat/webapps/ \ No newline at end of file diff --git a/javax-servlets-3/README.md b/javax-servlets-3/README.md index ff310b5928cb..1f4855f4b3cb 100644 --- a/javax-servlets-3/README.md +++ b/javax-servlets-3/README.md @@ -3,7 +3,8 @@ mvn package ## Run with Tomcat on Docker container: docker build --tag my-tomcat . + docker run -it --rm -p 8080:8080 my-tomcat -### Relevant Articles: +## Relevant Articles: - [Java Web Application Without Web.xml] diff --git a/javax-servlets-3/pom.xml b/javax-servlets-3/pom.xml index 2b4fc37fc4d2..8c339ce6d42a 100644 --- a/javax-servlets-3/pom.xml +++ b/javax-servlets-3/pom.xml @@ -31,6 +31,7 @@ 5.1.3.RELEASE + uppercasing-app org.apache.maven.plugins diff --git a/javax-servlets-3/src/main/java/com/baeldung/servlets3/web/filters/EmptyParamFilter.java b/javax-servlets-3/src/main/java/com/baeldung/servlets3/web/filters/EmptyParamFilter.java index 2c9f603d2c32..61a7e896ccff 100644 --- a/javax-servlets-3/src/main/java/com/baeldung/servlets3/web/filters/EmptyParamFilter.java +++ b/javax-servlets-3/src/main/java/com/baeldung/servlets3/web/filters/EmptyParamFilter.java @@ -8,9 +8,8 @@ import javax.servlet.ServletResponse; import javax.servlet.annotation.WebFilter; import java.io.IOException; -import java.io.PrintWriter; -@WebFilter(servletNames = { "uppercaseServlet" }, filterName = "emptyParamFilter") +@WebFilter(servletNames = { "uppercaseServlet" }, urlPatterns = "/uppercase") public class EmptyParamFilter implements Filter { @Override @@ -22,21 +21,13 @@ public void doFilter(ServletRequest servletRequest, ServletResponse servletRespo FilterChain filterChain) throws IOException, ServletException { String inputString = servletRequest.getParameter("input"); - if (inputString == null || inputString.isEmpty()) { - response(servletResponse); - } else { + if (inputString != null && inputString.matches("[A-Za-z0-9]+")) { filterChain.doFilter(servletRequest, servletResponse); + } else { + servletResponse.getWriter().println("Missing input parameter"); } } - private void response(ServletResponse response) throws IOException { - response.setContentType("text/html"); - - PrintWriter out = response.getWriter(); - - out.println("Missing input parameter"); - } - @Override public void destroy() { } From c636b0d4b73ba3954c973766ec8d1dc63357733f Mon Sep 17 00:00:00 2001 From: Joel Juarez Date: Thu, 21 Feb 2019 23:56:32 +0100 Subject: [PATCH 3/5] java web application without web.xml - servlets 3.0 --- javax-servlets-3/.gitignore | 6 --- javax-servlets-3/Dockerfile | 2 - javax-servlets-3/README.md | 10 ---- javax-servlets-3/pom.xml | 52 ------------------- .../servlets3/spring/AppInitializer.java | 27 ---------- .../servlets3/spring/config/AppConfig.java | 11 ---- .../controllers/UppercaseController.java | 17 ------ .../baeldung}/filters/EmptyParamFilter.java | 4 +- .../com/baeldung}/listeners/AppListener.java | 2 +- .../baeldung}/listeners/RequestListener.java | 2 +- .../baeldung}/servlets/CounterServlet.java | 6 +-- .../baeldung}/servlets/UppercaseServlet.java | 6 +-- 12 files changed, 6 insertions(+), 139 deletions(-) delete mode 100644 javax-servlets-3/.gitignore delete mode 100644 javax-servlets-3/Dockerfile delete mode 100644 javax-servlets-3/README.md delete mode 100644 javax-servlets-3/pom.xml delete mode 100644 javax-servlets-3/src/main/java/com/baeldung/servlets3/spring/AppInitializer.java delete mode 100644 javax-servlets-3/src/main/java/com/baeldung/servlets3/spring/config/AppConfig.java delete mode 100644 javax-servlets-3/src/main/java/com/baeldung/servlets3/spring/controllers/UppercaseController.java rename {javax-servlets-3/src/main/java/com/baeldung/servlets3/web => javax-servlets/src/main/java/com/baeldung}/filters/EmptyParamFilter.java (88%) rename {javax-servlets-3/src/main/java/com/baeldung/servlets3/web => javax-servlets/src/main/java/com/baeldung}/listeners/AppListener.java (91%) rename {javax-servlets-3/src/main/java/com/baeldung/servlets3/web => javax-servlets/src/main/java/com/baeldung}/listeners/RequestListener.java (94%) rename {javax-servlets-3/src/main/java/com/baeldung/servlets3/web => javax-servlets/src/main/java/com/baeldung}/servlets/CounterServlet.java (78%) rename {javax-servlets-3/src/main/java/com/baeldung/servlets3/web => javax-servlets/src/main/java/com/baeldung}/servlets/UppercaseServlet.java (78%) diff --git a/javax-servlets-3/.gitignore b/javax-servlets-3/.gitignore deleted file mode 100644 index dfbd0632874e..000000000000 --- a/javax-servlets-3/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -# Created by .ignore support plugin (hsz.mobi) -.idea -classes -target -*.iml -out \ No newline at end of file diff --git a/javax-servlets-3/Dockerfile b/javax-servlets-3/Dockerfile deleted file mode 100644 index 27d1450acbbf..000000000000 --- a/javax-servlets-3/Dockerfile +++ /dev/null @@ -1,2 +0,0 @@ -FROM tomcat -ADD ./target/uppercasing-app.war /usr/local/tomcat/webapps/ \ No newline at end of file diff --git a/javax-servlets-3/README.md b/javax-servlets-3/README.md deleted file mode 100644 index 1f4855f4b3cb..000000000000 --- a/javax-servlets-3/README.md +++ /dev/null @@ -1,10 +0,0 @@ -## Build with maven: -mvn package - -## Run with Tomcat on Docker container: -docker build --tag my-tomcat . - -docker run -it --rm -p 8080:8080 my-tomcat - -## Relevant Articles: -- [Java Web Application Without Web.xml] diff --git a/javax-servlets-3/pom.xml b/javax-servlets-3/pom.xml deleted file mode 100644 index 8c339ce6d42a..000000000000 --- a/javax-servlets-3/pom.xml +++ /dev/null @@ -1,52 +0,0 @@ - - - 4.0.0 - javax-servlets-3 - 1.0-SNAPSHOT - javax-servlets-3 - war - - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - - - - - - javax.servlet - javax.servlet-api - ${javax.servlet-api.version} - - - org.springframework - spring-webmvc - ${spring.version} - - - - 4.0.1 - 5.1.3.RELEASE - - - uppercasing-app - - - org.apache.maven.plugins - maven-war-plugin - 3.1.0 - - - default-war - prepare-package - - false - - - - - - - diff --git a/javax-servlets-3/src/main/java/com/baeldung/servlets3/spring/AppInitializer.java b/javax-servlets-3/src/main/java/com/baeldung/servlets3/spring/AppInitializer.java deleted file mode 100644 index 837d439cf409..000000000000 --- a/javax-servlets-3/src/main/java/com/baeldung/servlets3/spring/AppInitializer.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.baeldung.servlets3.spring; - -import com.baeldung.servlets3.spring.config.AppConfig; -import org.springframework.web.WebApplicationInitializer; -import org.springframework.web.context.ContextLoaderListener; -import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; -import org.springframework.web.servlet.DispatcherServlet; - -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.ServletRegistration; - -public class AppInitializer implements WebApplicationInitializer { - @Override - public void onStartup(ServletContext servletContext) throws ServletException { - AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); - context.register(AppConfig.class); - - servletContext.addListener(new ContextLoaderListener(context)); - - ServletRegistration.Dynamic dispatcher = servletContext.addServlet("spring-dispatcher", - new DispatcherServlet(context)); - - dispatcher.setLoadOnStartup(1); - dispatcher.addMapping("/spring/*"); - } -} diff --git a/javax-servlets-3/src/main/java/com/baeldung/servlets3/spring/config/AppConfig.java b/javax-servlets-3/src/main/java/com/baeldung/servlets3/spring/config/AppConfig.java deleted file mode 100644 index 0088bad77099..000000000000 --- a/javax-servlets-3/src/main/java/com/baeldung/servlets3/spring/config/AppConfig.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.baeldung.servlets3.spring.config; - -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.config.annotation.EnableWebMvc; - -@Configuration -@EnableWebMvc -@ComponentScan("com.baeldung.servlets3.spring") -public class AppConfig { -} diff --git a/javax-servlets-3/src/main/java/com/baeldung/servlets3/spring/controllers/UppercaseController.java b/javax-servlets-3/src/main/java/com/baeldung/servlets3/spring/controllers/UppercaseController.java deleted file mode 100644 index 74585e6b5e1d..000000000000 --- a/javax-servlets-3/src/main/java/com/baeldung/servlets3/spring/controllers/UppercaseController.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.baeldung.servlets3.spring.controllers; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -@RestController -@RequestMapping("/uppercase") -public class UppercaseController { - - @GetMapping(produces = "text/html") - public String getUppercase(@RequestParam(required = false)String param) { - String response = param != null ? param.toUpperCase() : "Missing param"; - return "From Spring: " + response; - } -} diff --git a/javax-servlets-3/src/main/java/com/baeldung/servlets3/web/filters/EmptyParamFilter.java b/javax-servlets/src/main/java/com/baeldung/filters/EmptyParamFilter.java similarity index 88% rename from javax-servlets-3/src/main/java/com/baeldung/servlets3/web/filters/EmptyParamFilter.java rename to javax-servlets/src/main/java/com/baeldung/filters/EmptyParamFilter.java index 61a7e896ccff..b0b539223797 100644 --- a/javax-servlets-3/src/main/java/com/baeldung/servlets3/web/filters/EmptyParamFilter.java +++ b/javax-servlets/src/main/java/com/baeldung/filters/EmptyParamFilter.java @@ -1,4 +1,4 @@ -package com.baeldung.servlets3.web.filters; +package com.baeldung.filters; import javax.servlet.Filter; import javax.servlet.FilterChain; @@ -9,7 +9,7 @@ import javax.servlet.annotation.WebFilter; import java.io.IOException; -@WebFilter(servletNames = { "uppercaseServlet" }, urlPatterns = "/uppercase") +@WebFilter(urlPatterns = "/uppercase") public class EmptyParamFilter implements Filter { @Override diff --git a/javax-servlets-3/src/main/java/com/baeldung/servlets3/web/listeners/AppListener.java b/javax-servlets/src/main/java/com/baeldung/listeners/AppListener.java similarity index 91% rename from javax-servlets-3/src/main/java/com/baeldung/servlets3/web/listeners/AppListener.java rename to javax-servlets/src/main/java/com/baeldung/listeners/AppListener.java index d61af65c31d9..ed16dd165442 100644 --- a/javax-servlets-3/src/main/java/com/baeldung/servlets3/web/listeners/AppListener.java +++ b/javax-servlets/src/main/java/com/baeldung/listeners/AppListener.java @@ -1,4 +1,4 @@ -package com.baeldung.servlets3.web.listeners; +package com.baeldung.listeners; import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; diff --git a/javax-servlets-3/src/main/java/com/baeldung/servlets3/web/listeners/RequestListener.java b/javax-servlets/src/main/java/com/baeldung/listeners/RequestListener.java similarity index 94% rename from javax-servlets-3/src/main/java/com/baeldung/servlets3/web/listeners/RequestListener.java rename to javax-servlets/src/main/java/com/baeldung/listeners/RequestListener.java index aeebf482fb8e..7f0c37b66687 100644 --- a/javax-servlets-3/src/main/java/com/baeldung/servlets3/web/listeners/RequestListener.java +++ b/javax-servlets/src/main/java/com/baeldung/listeners/RequestListener.java @@ -1,4 +1,4 @@ -package com.baeldung.servlets3.web.listeners; +package com.baeldung.listeners; import javax.servlet.ServletContext; import javax.servlet.ServletRequestEvent; diff --git a/javax-servlets-3/src/main/java/com/baeldung/servlets3/web/servlets/CounterServlet.java b/javax-servlets/src/main/java/com/baeldung/servlets/CounterServlet.java similarity index 78% rename from javax-servlets-3/src/main/java/com/baeldung/servlets3/web/servlets/CounterServlet.java rename to javax-servlets/src/main/java/com/baeldung/servlets/CounterServlet.java index 4bb92bbf7729..b9ea55de735b 100644 --- a/javax-servlets-3/src/main/java/com/baeldung/servlets3/web/servlets/CounterServlet.java +++ b/javax-servlets/src/main/java/com/baeldung/servlets/CounterServlet.java @@ -1,4 +1,4 @@ -package com.baeldung.servlets3.web.servlets; +package com.baeldung.servlets; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; @@ -10,10 +10,6 @@ @WebServlet(urlPatterns = "/counter", name = "counterServlet") public class CounterServlet extends HttpServlet { - public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { - doGet(request, response); - } - public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { response.setContentType("text/html"); diff --git a/javax-servlets-3/src/main/java/com/baeldung/servlets3/web/servlets/UppercaseServlet.java b/javax-servlets/src/main/java/com/baeldung/servlets/UppercaseServlet.java similarity index 78% rename from javax-servlets-3/src/main/java/com/baeldung/servlets3/web/servlets/UppercaseServlet.java rename to javax-servlets/src/main/java/com/baeldung/servlets/UppercaseServlet.java index 9b948cd99429..0357ab28b51b 100644 --- a/javax-servlets-3/src/main/java/com/baeldung/servlets3/web/servlets/UppercaseServlet.java +++ b/javax-servlets/src/main/java/com/baeldung/servlets/UppercaseServlet.java @@ -1,4 +1,4 @@ -package com.baeldung.servlets3.web.servlets; +package com.baeldung.servlets; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; @@ -10,10 +10,6 @@ @WebServlet(urlPatterns = "/uppercase", name = "uppercaseServlet") public class UppercaseServlet extends HttpServlet { - public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { - doGet(request, response); - } - public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { String inputString = request.getParameter("input").toUpperCase(); From 6a36c90be5f8cde0e93f4bd44ed8840e21797e37 Mon Sep 17 00:00:00 2001 From: Joel Juarez Date: Sat, 23 Feb 2019 22:07:49 +0100 Subject: [PATCH 4/5] removed content type set in servlets --- .../src/main/java/com/baeldung/servlets/CounterServlet.java | 2 -- .../src/main/java/com/baeldung/servlets/UppercaseServlet.java | 2 -- 2 files changed, 4 deletions(-) diff --git a/javax-servlets/src/main/java/com/baeldung/servlets/CounterServlet.java b/javax-servlets/src/main/java/com/baeldung/servlets/CounterServlet.java index b9ea55de735b..a11f084db2e1 100644 --- a/javax-servlets/src/main/java/com/baeldung/servlets/CounterServlet.java +++ b/javax-servlets/src/main/java/com/baeldung/servlets/CounterServlet.java @@ -11,8 +11,6 @@ public class CounterServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { - response.setContentType("text/html"); - PrintWriter out = response.getWriter(); int count = (int)request.getServletContext().getAttribute("counter"); diff --git a/javax-servlets/src/main/java/com/baeldung/servlets/UppercaseServlet.java b/javax-servlets/src/main/java/com/baeldung/servlets/UppercaseServlet.java index 0357ab28b51b..766ec2e6ff09 100644 --- a/javax-servlets/src/main/java/com/baeldung/servlets/UppercaseServlet.java +++ b/javax-servlets/src/main/java/com/baeldung/servlets/UppercaseServlet.java @@ -13,8 +13,6 @@ public class UppercaseServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { String inputString = request.getParameter("input").toUpperCase(); - response.setContentType("text/html"); - PrintWriter out = response.getWriter(); out.println(inputString); From b7c109246031cad59efce302ac4e0b650ac865c0 Mon Sep 17 00:00:00 2001 From: KevinGilmore Date: Sat, 16 Mar 2019 17:56:54 -0500 Subject: [PATCH 5/5] BAEL-2711: Add spring-boot-angular module to pom.xml (#6492) * BAEL-2246: add link back to article * BAEL-2174: rename core-java-net module to core-java-networking * BAEL-2174: add link back to article * BAEL-2363 BAEL-2337 BAEL-1996 BAEL-2277 add links back to articles * BAEL-2367: add link back to article * BAEL-2335: add link back to article * BAEL-2413: add link back to article * Update README.MD * BAEL-2577: add link back to article * BAEL-2490: add link back to article * BAEL-2471: add link back to article * BAEL-2583: add link back to article * BAEL-2738: add link back to article * BAEL-2711: Add spring-boot-angular module to root pom * BAEL-2544 BAEL-2711 BAEL-2575 BAEL-2657 Add links back to articles --- core-kotlin-2/README.md | 2 ++ java-streams-2/README.md | 3 +++ persistence-modules/spring-boot-persistence/README.MD | 1 + spring-boot-angular/README.md | 3 +++ 4 files changed, 9 insertions(+) create mode 100644 java-streams-2/README.md create mode 100644 spring-boot-angular/README.md diff --git a/core-kotlin-2/README.md b/core-kotlin-2/README.md index 8d22c4f1a85f..da2f7548d911 100644 --- a/core-kotlin-2/README.md +++ b/core-kotlin-2/README.md @@ -2,3 +2,5 @@ - [Void Type in Kotlin](https://www.baeldung.com/kotlin-void-type) - [How to use Kotlin Range Expressions](https://www.baeldung.com/kotlin-ranges) +- [Split a List into Parts in Kotlin](https://www.baeldung.com/kotlin-split-list-into-parts) + diff --git a/java-streams-2/README.md b/java-streams-2/README.md new file mode 100644 index 000000000000..83ef97686faf --- /dev/null +++ b/java-streams-2/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: +- [Guide to Stream.reduce()](https://www.baeldung.com/java-stream-reduce) + diff --git a/persistence-modules/spring-boot-persistence/README.MD b/persistence-modules/spring-boot-persistence/README.MD index f62ca57a1923..ee7c2e298ee0 100644 --- a/persistence-modules/spring-boot-persistence/README.MD +++ b/persistence-modules/spring-boot-persistence/README.MD @@ -7,3 +7,4 @@ - [Hibernate Field Naming with Spring Boot](https://www.baeldung.com/hibernate-field-naming-spring-boot) - [Integrating Spring Boot with HSQLDB](https://www.baeldung.com/spring-boot-hsqldb) - [Configuring a DataSource Programmatically in Spring Boot](https://www.baeldung.com/spring-boot-configure-data-source-programmatic) +- [Resolving “Failed to Configure a DataSource” Error](https://www.baeldung.com/spring-boot-failed-to-configure-data-source) diff --git a/spring-boot-angular/README.md b/spring-boot-angular/README.md new file mode 100644 index 000000000000..cfc1ea69f4a8 --- /dev/null +++ b/spring-boot-angular/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: +- [Building a Web Application with Spring Boot and Angular](https://www.baeldung.com/spring-boot-angular-web) +