IntelliJ open source
[Logo] JavaRanch » JavaRanch Saloon
  Search | FAQ | Recent Topics | Hot Topics
Register / Login


Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Servlets
 
RSS feed
 
New topic
Author

access specifier to Servlet class

Pavan Kumar Reddy
Greenhorn

Joined: Dec 11, 2009
Messages: 12

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
Sheriff

Joined: Mar 22, 2005
Messages: 26783

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?

Java web chartsImageJ PluginsSpecification URLsJava FAQs
Pavan Kumar Reddy
Greenhorn

Joined: Dec 11, 2009
Messages: 12

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
Bartender

Joined: Sep 29, 2008
Messages: 6861

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.

Consultant/Trainer | Polyglottal Developer | Struts Committer/PMC | Struts 2 Web Application Development
 
jQuery in Action
 
 
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Servlets
 
RSS feed
 
New topic
replay challenge

.