Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

If Servlet load-on-startup, Does it also need servlet-mapping?

 
Robert Paris
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a servlet that I want the container to load on startup. However, I do not want anyone to be able to load the servlet from a browser. In other words, I don't want to map the servlet to anything. Is it possible to do this? If I don't provide a servlet-mapping, is it still available from a url by it's name?
 
Robert Paris
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The answer is no! Yay! OK, if you have:

But no mapping, it WILL be loaded by the container, but will NOT be accessible by any other means. Cool.
 
Mark Howard
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Robert
The servlet is still accessible from a URL. Defining a servlet mapping is optional, and is simply a means to determine which servlets should handle which URL patterns.
Your servlet could be accessed from the browser address window, for instance, with:
 
Robert Paris
Ranch Hand
Posts: 585
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried that and it didn't work. I can't access my servlet from a browser. I tried doing it like you suggested. i also tried doing it with "webapp/servletname" and not the intermediary "servlet" folder and I still couldn't find it. I can't load the servlet from a url. Why are you still able to? Try checking your web.xml both in the main root and the webapp you're using and also the server config. My webapp files are NOT under the root of my servlet engine's folder. They're elsewhere on the computer and mapped to a specific virtual host.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic