aspose file tools*
The moose likes IDEs, Version Control and other tools and the fly likes Issue in eclipse regarding packages and servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "Issue in eclipse regarding packages and servlets" Watch "Issue in eclipse regarding packages and servlets" New topic
Author

Issue in eclipse regarding packages and servlets

akaash singh
Ranch Hand

Joined: Jul 04, 2009
Posts: 45
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

Joined: Sep 08, 2007
Posts: 3071
    
  33

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.


Mohamed Sanaulla | My Blog
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61414
    
  67

Please be sure to ask IDE questions in the IDEs forum. I have moved this post there for you.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Prakash Mani - Attur
Ranch Hand

Joined: Oct 08, 2009
Posts: 100
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

Joined: Jul 04, 2009
Posts: 45
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

Joined: Jul 04, 2009
Posts: 45

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
 
subject: Issue in eclipse regarding packages and servlets