aspose file tools*
The moose likes Servlets and the fly likes access specifier to Servlet class 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 » Java » Servlets
Bookmark "access specifier to Servlet class" Watch "access specifier to Servlet class" New topic
Author

access specifier to Servlet class

Pavan Kumar Reddy
Greenhorn

Joined: Dec 11, 2009
Posts: 13
hi to all,

why should we put public access specifer for any servlet class which extends GenericServlet or implement Servlet interface.
Why such a specification given by Servlet Container.where the servlet container executes,is servlet container and our class files run in same package or different package,if different ,i want to put my servlet in the same package what servlet continer class files are there ,then is my servlet work without writing public access specifier.

Same doubt arised for me in Applets also.

Thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42267
    
  64
You should absolutely not put your classes into existing packages of other libraries; that is a problem waiting to happen. That means any Java code needs to be public in order to be called from unrelated code. This is true everywhere, not just in applets and servlets. Do you see an actual problem with declaring methods to be public?


Ping & DNS - my free Android networking tools app
Pavan Kumar Reddy
Greenhorn

Joined: Dec 11, 2009
Posts: 13
thanks for giving answer,but still i have some more doubts after understanding your best answer.
1.what type of problems can we get when i put my class file inside Servlet Container classes itself,just for testing.
2.If they are in differnet packages only there is a problem with access specifier,if i put in same what is the problem.
3.From which location ServletContainer executes and where Our Servlet object created.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Pavan Kumar Reddy wrote:1.what type of problems can we get when i put my class file inside Servlet Container classes itself,just for testing.

Name collisions: that's why packages exist in the first place--to give you a namespace unique to your code.

I wasn't really sure what your other questions meant.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: access specifier to Servlet class