gradle / gradle/guides

Slash required on urlPatterns for @WebServlet annotations

Open
#285 0 comments 0 reactions 0 assignees View on GitHub
in:building-java-web-applications
Dominant language
Java
Stars
48
Forks
36
Avg merge
7h 37m
Merged PRs (30d)
8

Description

@pla1 commented on [Thu May 30 2019](https://github.com/gradle-guides/building-java-web-applications/issues/25)

Using Apache Tomcat/9.0.20 servlet API 4.0.1 I had to change
`@WebServlet(name = "HelloServlet", urlPatterns = {"hello"}, loadOnStartup = 1)`
to
`@WebServlet(name = "HelloServlet", urlPatterns = {"/hello"}, loadOnStartup = 1)`

---

@ETLJ commented on [Tue Nov 12 2019](https://github.com/gradle-guides/building-java-web-applications/issues/25#issuecomment-552702763)

That fixed the problem I was having too. Tomcat/7.0.86 servlet-api:3.1.0

`21:07:11 ERROR A child container failed during start
java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[/awebdemo]]
at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[na:na]
at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191) ~[na:na]
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1241) ~[tomcat-embed-core-7.0.86.jar:7.0.86]
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:819) ~[tomcat-embed-core-7.0.86.jar:7.0.86]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145) ~[tomcat-embed-core-7.0.86.jar:7.0.86]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1702) ~[tomcat-embed-core-7.0.86.jar:7.0.86]
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1692) ~[tomcat-embed-core-7.0.86.jar:7.0.86]
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[/awebdemo]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:162) ~[tomcat-embed-core-7.0.86.jar:7.0.86]
... 6 common frames omitted
Caused by: java.lang.IllegalArgumentException: Invalid hello in servlet mapping`

Contributor guide

No contributing guide indexed for this repository

Research direction

Search the guide for the @WebServlet example containing urlPatterns = {"hello"}. Update the example to use the required leading slash, then verify that the documented application configuration matches the servlet URL pattern expected by Tomcat.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.