Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't java webapps have 2 webcontexts?

Tags:

java

jetty

A java webapp must choose between either static context or "webcontext". Why do we need a webcontext just for a web server like jetty and why must we route everything to the same "webcontext" ?

like image 301
Niklas Rosencrantz Avatar asked Mar 21 '23 08:03

Niklas Rosencrantz


1 Answers

Because Jetty is a JEE servlet container and in the JEE world there is a one to one relationship between a webapplication and the web context. The intention is to be able to run several independent webapplications within the same servlet container. So it is easy to route to the appropriate webapplication by the first part of the URL path.

Theoretically it would be possible to declare more than one webcontext for a webapplication but it is specified otherwise. See section 10.2 "Relationship to ServletContext" in Java Servlet Specification 3.1:

The servlet container must enforce a one to one correspondence between a Web application and a ServletContext. A ServletContext object provides a servlet with its view of the application.

like image 133
vanje Avatar answered Mar 27 '23 11:03

vanje