In my web.xml of my simple app i have
<servlet>
<servlet-name>HelloServlet</servlet-name>
<servlet-class>HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloServlet</servlet-name>
<url-pattern>/Hai</url-pattern>
</servlet-mapping>
and now if I have
<url-pattern>/*</url-pattern>
in security constraint it asks for password when I try to get to my deployed app, but when I change it to
<url-pattern>/Projekt/*</url-pattern>
and try to enter Projekt/Hai I am not asked for my password, why?
The url-pattern that you specify in web.xml is always a pattern that is relative to the context path of the webapp. So,
/Projekt/*means all the URLs under/Projekt, under the context path of the application.Since your app is deployed un
/Projekt, it means that this url-pattern matches the URLhttp://localhost:8080/Projekt/projekt/Hai. It doesn’t matchhttp://localhost:8080/Projekt/Hai, because this URL, when written relatively to the context path, is/Hai, which doesn’t matches the pattern/Projekt/*.Good rule of thumb: nothing in the code or deployment descriptor of a webapp should ever depend on the context path chosen to deploy the application. Everything should always be specified relatively to this context path.