aspose file tools*
The moose likes Servlets and the fly likes How can I remove java package (classpath location) information out of my URL? on Tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How can I remove java package (classpath location) information out of my URL? on Tomcat" Watch "How can I remove java package (classpath location) information out of my URL? on Tomcat" New topic
Author

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

Steven Mac
Greenhorn

Joined: May 27, 2010
Posts: 13
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

Joined: Apr 26, 2007
Posts: 249
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
Marshal

Joined: Mar 22, 2005
Posts: 42648
    
  65
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.


Ping & DNS - my free Android networking tools app
Steven Mac
Greenhorn

Joined: May 27, 2010
Posts: 13
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

Joined: Apr 26, 2007
Posts: 249
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

Joined: May 27, 2010
Posts: 13
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

Joined: Apr 26, 2007
Posts: 249
Cheers mate,... and hey, welcome to the ranch !!!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Invoker servlet BAD. Hasn't Tomcat been shipping with it turned off by default for years now?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can I remove java package (classpath location) information out of my URL? on Tomcat