skystar7
skystar7

Reputation: 4597

RequestDispatcher and paths

When dealing with RequestDispatcher and resource paths, is the paths are build mainly upon <url-pattern> element? even though the resources are in different packages

For example: I have on servlet defined under:

 <url-pattern>/handlers/FrontHandler</url-pattern>

and another resource in <url-pattern>/handlers/sub/SecondHandler</url-pattern> so this resource is relative to the previous one even though the two classes in different packages?

Am i understand this correctly? Also do i have to use ../ to get one level up like regular paht navigation?

Thanks

Upvotes: 0

Views: 884

Answers (1)

JB Nizet
JB Nizet

Reputation: 692271

The javadoc says:

The pathname specified may be relative, although it cannot extend outside the current servlet context. If the path begins with a "/" it is interpreted as relative to the current context root.

So the path has nothing to do with class names, and everything to do with what resource (static, like an html file, or dynamic, like a servlet mapped to a given url pattern) is located at the given path.

I would avoid using relative paths: it's hard to know to which absolute path they resolve, and they're fragile because if you map your servlet to another URL, they will break.

Upvotes: 1

Related Questions