1

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?

2
  • Under which context path is your application deployed, and what's the complete URL you're using when it doesn't ask for a password? Commented Feb 7, 2012 at 21:39
  • <Context docBase="Projekt.war" path="/Projekt"/>, I use localhost:8080/Projekt/Hai Commented Feb 7, 2012 at 21:45

1 Answer 1

4

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 URL http://localhost:8080/Projekt/projekt/Hai. It doesn't match http://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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.