• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can I remove java package (classpath location) information out of my URL? on Tomcat

 
Steven Mac
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everyone,

I am using an Apache Tomcat web platform where my servlets are deployed. Right now, all access is by designation of package information.servlet.

Example:
/servlet/com.abc.test.MyServlet

how can I remove com.abc.test. (package/classpath information) and just have the application use servlet/MyServlet call up which references com.abc.test.MyServlet? I have roughly 30 different servlets as part of the application and will grow as more is added - what can be done to make this look a little cleaner to the end-user without getting int a lot of maintenance.


Thank you for your assistance and expertise on the matter.

Steven
 
Dawn Charangat
Ranch Hand
Posts: 249
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can map the servlet name/class to the URL of your preference in the web.xml file, and you should be good to go.
Find more details here: http://stackoverflow.com/questions/234210/can-anyone-explain-servlet-mapping
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

It seems that you're using the http://faq.javaranch.com/java/InvokerServlet - don't do that. Servlets should be properly mapped in the web.xml file, even if there are quite a few of them.

Or look into using a web framework that doesn't require you to create servlets, maybe something like Struts 2 or Stripes.
 
Steven Mac
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I took a look at the link you posted. Would this require that I have to specify for each servlet that I have or am I not seeing the right solution? What must be changed in the web.xml so that all of these servlets will remove the package/path information to the servlet class file?
 
Dawn Charangat
Ranch Hand
Posts: 249
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For each servlet, if you want it to be uniquely reached by a URL, you will have to map it in the web.xml separately.

However, if you want multiple URLs to point to the same servlet, that can be done as well (by giving * as the wildcard to denote URL).
 
Steven Mac
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After doing some reading of what you sent, It looks like for final cleanup and added security I will want to declare all of the servlets.
 
Dawn Charangat
Ranch Hand
Posts: 249
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cheers mate,... and hey, welcome to the ranch !!!
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Invoker servlet BAD. Hasn't Tomcat been shipping with it turned off by default for years now?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic