Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

access specifier to Servlet class

 
Pavan Kumar Reddy
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Pavan Kumar Reddy
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic