parent
445fee41b3
commit
fc88c99537
|
@ -1,2 +1,2 @@
|
|||
FROM tomcat
|
||||
ADD ./target/javax-servlets-3-1.0-SNAPSHOT.war /usr/local/tomcat/webapps/
|
||||
ADD ./target/uppercasing-app.war /usr/local/tomcat/webapps/
|
|
@ -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]
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
<spring.version>5.1.3.RELEASE</spring.version>
|
||||
</properties>
|
||||
<build>
|
||||
<finalName>uppercasing-app</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
|
|
|
@ -8,9 +8,8 @@ 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")
|
||||
@WebFilter(servletNames = { "uppercaseServlet" }, urlPatterns = "/uppercase")
|
||||
public class EmptyParamFilter implements Filter {
|
||||
|
||||
@Override
|
||||
|
@ -22,21 +21,13 @@ public class EmptyParamFilter implements Filter {
|
|||
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() {
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue