• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Why should we import javax.servlet.http.* when we already imported javax.servlet.*?

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Is it necessary to import javax.servlet.http.* when we have already imported javax.servlet.*? Does javax.servlet.* contains http?

Please clarify my doubt..

Thanks in Advance
Nagaraj
 
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes it is neccessary.
'javax.servlet.http' is a different package than 'javax.servlet'.

By using import javax.servlet.*, you 'automatically import all of the public type names declared in the [javax.servlet] package'.
 
Nagaraj Shivaklara
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jan Cumps wrote:Yes it is neccessary.
'javax.servlet.http' is a different package than 'javax.servlet'.

By using import javax.servlet.*, you 'automatically import all of the public type names declared in the [javax.servlet] package'.



Thanks Jan for clarifying these are two different packages, but any idea why the name convention follows like this javax.servlet.http? by looking at it we can say http is under javax.servlet. It is just for my curiosity, if you have free time then only reply...
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's just how Java works. Even though package names can have common prefixes, they are still separate packages.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java's packages are not hierarchical - the package javax.servlet.http is not a subpackage of javax.servlet. In fact, the notion of "subpackages" doesn't exist at all, even though it's easy to assume so because of the directory structure.

You should the packages javax.servlet and javax.servlet.http are two totally separate packages that happen to have a name that starts with the same prefix.
 
Nagaraj Shivaklara
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:That's just how Java works. Even though package names can have common prefixes, they are still separate packages.



Thank you..
 
Nagaraj Shivaklara
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jesper Young wrote:Java's packages are not hierarchical - the package javax.servlet.http is not a subpackage of javax.servlet. In fact, the notion of "subpackages" doesn't exist at all, even though it's easy to assume so because of the directory structure.

You should the packages javax.servlet and javax.servlet.http are two totally separate packages that happen to have a name that starts with the same prefix.



Thank you Jesper
 
reply
    Bookmark Topic Watch Topic
  • New Topic