• 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

Issue in eclipse regarding packages and servlets

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

I using eclipse . I created a Dynamic Web project . I put the servlets inside packages in the source folder and the html and JSPs in the web content folder. I am not able to add two servlets with the same name inside different packages . A prompt is thrown saying that a servlet with name already exists ?

Why is it so ? Shouldn't I be able to add two servlets with the same name as long as I put them in different packages ?

Also suppose I create a servlet "servA" iniside a package named "p1" . I have to specify the servA in the action attribute of some jsp . How do i specify it ?

- as action ="p1.servA" (this did not work)
or
- simply as : action="servA" ( this worked)

Why is it so ? Isn't the first way correct ?

Are these issues related to eclipse ?

Thanks and Regards
Akash
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

akaash singh wrote:- as action ="p1.servA" (this did not work)
or
- simply as : action="servA" ( this worked)



This refers to the Servlet and URL mapping in your web.xml file and not the class name directly.

akaash singh wrote:
Why is it so ? Shouldn't I be able to add two servlets with the same name as long as I put them in different packages ?


Why would you need to have Servlets with the same name? Servlets are used as controllers for processing your requests.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please be sure to ask IDE questions in the IDEs forum. I have moved this post there for you.
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you cannot name two servlets with same name as long as the servlet class has public midifier...also you cannot remove the public modifier for servlet since your servlet been called by the container..
 
akaash singh
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But that's that's whole purpose of packages that two packages can have classes of same name as without conflict. And of course its possible if we don't use an IDE. Is this a eclipse specific thing ?
 
akaash singh
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

akaash singh wrote:
Why is it so ? Shouldn't I be able to add two servlets with the same name as long as I put them in different packages ?


Why would you need to have Servlets with the same name? Servlets are used as controllers for processing your requests.

Suppose I create two servlets with the same name in different packages and the actual package to be used depends on some condition . I know this isn't a very good example but cooked it up just for the sake of an example .
reply
    Bookmark Topic Watch Topic
  • New Topic