This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Issue in eclipse regarding packages and servlets

 
akaash singh
Ranch Hand
Posts: 45
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Mohamed Sanaulla
Saloon Keeper
Pie
Posts: 3159
33
Google App Engine Java Ruby
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64185
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to ask IDE questions in the IDEs forum. I have moved this post there for you.
 
Prakash Mani - Attur
Ranch Hand
Posts: 100
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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 .
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic