• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

tomcat 7 servlet examples work but I don't know why

 
Greenhorn
Posts: 21
Mac OS X MySQL Database Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I installed tomcat 7 on apache on os x 10.8 so far so good, checked out the examples the all worked. so whats the problem?
I don't understand why they work.

the path on the tomcat server is /Library/Tomcat/webapps/examples/WEB-INF/classes/HelloWorldExample.class

the link on the servlet example page is http://localhost:8080/examples/servlets/servlet/HelloWorldExample

There is no path for examples/servlets/servlet there is a path for examples/servlets but the only thing in that directory is helloworld.html and
nothing seems to point to it.

I have tried numerous times to create my own HelloWorldExample but I'm just not getting it. Can someone tell me how
http://localhost:8080/examples/servlets/servlet/HelloWorldExample gets to /Library/Tomcat/webapps/examples/WEB-INF/classes/HelloWorldExample.class


 
Sheriff
Posts: 67269
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The configuration to map servlets to their URLs is in the web app's deployment descriptor (web.xml).

P.S. It is considered amateurish to use the word "servlet" in a mapping despite the examples.
 
Ranch Hand
Posts: 1067
2
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look in your config files. Start with server.xml.
 
Bear Bibeault
Sheriff
Posts: 67269
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

William Barnes wrote:Look in your config files. Start with server.xml.



Server.xml has little to do with servlet mapping. The only influence it might have is when configuring multiple hosts, but that will have no influence on the servlet path.
 
bob von ilten
Greenhorn
Posts: 21
Mac OS X MySQL Database Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did find the web.xml file and there did not seem to be anything pointing to the actual location

<servlet>
<servlet-name>HelloWorldExample</servlet-name>
<servlet-class>HelloWorldExample</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>HelloWorldExample</servlet-name>
<url-pattern>/servlets/servlet/HelloWorldExample</url-pattern>
</servlet-mapping>
 
Bear Bibeault
Sheriff
Posts: 67269
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The <servlet-class> element identifies the class of the servlet within the classpath. This is a bad example because the servlet is not in a package and it should be.

You will never see a file path to the servlet, or any other Java class, because that's not the way Java works. Classes are searched for in the classpath, not a file path. The classes in the package structure under WEB-INF/classes are automatically added to the web app's classpath. (As are any jars in WEB-INF/lib).
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!