changing default directory for servlets in tomcat

Hi guys

I have a huge problem getting tomcat to serve servlets from another directory than the default.

Tomcat 5.5.17, apache 2.0.54 using mod_proxy

Currently it serves .jsp from the directory /home/lennart/www/blog/test without any problems
What I am trying to accomplish is to serve a servlet from /home/lennart/www/blog/test/WEB-INF/classes/HelloWorldExample

the testpage can be reached at megahooked.com/test/test.jsp

Code from the page <jsp:include page="HelloWorldExample" flush="true" />

One interesting thing is that if I uncommect the web.xml part below it will stot serving jsp files.

Relevant entries in the config files
httpd.conf
<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    ServerName megahooked.com
    DocumentRoot /home/lennart/www/blog
    ErrorLog /home/lennart/www/error.log

#Reverse Proxy

ProxyRequests Off

<Proxy *>
Order deny,allow
Allow from all
</Proxy>

ProxyPass /jsp-examples http://localhost:8081/jsp-examples
ProxyPassReverse /jsp-examples http://localhost:8081/jsp-examples

ProxyPass /test http://localhost:8081/test
ProxyPassReverse /test http://localhost:8081/test

server.xml
<Connector port="8081"
            proxyName="megahooked.com"
            proxyPort="80" />

    <!--
    <Context path="/test" docBase="" debug="0"
            reloadable="true" />
    -->

web.xml
<!--
   <servlet>
        <servlet-name>HelloWorldExample</servlet-name>
        <servlet-class>HelloWorldExample</servlet-class>
         <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>HelloWorldExample</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    -->

Thanks
Joachim

LVL 4
joachimcAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

fargoCommented:
it is recommended to keep the servlet or any other java classes in under WEB-INF/classes with packages.

For ex: the class HelloWorldExample should go under some package say for ex: com.company.servlets.HelloWorldExample and do adjust the servlet-class in the web.xml with packages.

do check the url pattern..it should have the same name for your case.
<servlet-name>HelloWorldExample</servlet-name>
<url-pattern>/HelloWorldExample</url-pattern>


restart the tomcat and things should work.
0
sleep_furiouslyCommented:
First of all, the reason JSPs stop working when you uncomment the section of your application's web.xml is you have overriden the default servlet and sent everything to HelloWorldExample:

    <servlet-mapping>
        <servlet-name>HelloWorldExample</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

Which is saying for every request location beginning with "/" (in other words, all of them) send them to HelloWorldExample servlet.

What you are overriding is some settings in $TOMCAT/conf/web.xml:

    <!-- The mapping for the default servlet -->
    <servlet-mapping>
        <servlet-name>default</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <!-- The mapping for the JSP servlet -->
    <servlet-mapping>
        <servlet-name>jsp</servlet-name>
        <url-pattern>*.jsp</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>jsp</servlet-name>
        <url-pattern>*.jspx</url-pattern>
    </servlet-mapping>

So, looking at your proxy config and jsp include, it looks like what you want in your application's web XML is probably something like:

    <servlet-mapping>
        <servlet-name>HelloWorldExample</servlet-name>
        <url-pattern>/HelloWorldExample</url-pattern>
    </servlet-mapping>

Second, can you clarify "to serve a servlet from /home/lennart/www/blog/test/WEB-INF/classes/HelloWorldExample"

Is that last path segment a directory name?  In other words, do you have a class file like:
  /home/lennart/www/blog/test/WEB-INF/classes/HelloWorldExample/HelloWorldExample.class  ?

If so, then your servlet-class should reflect that.  In other words:

   <servlet>
        <servlet-name>HelloWorldExample</servlet-name>
        <servlet-class>HelloWorldExample.HelloWorldExample</servlet-class>
         <load-on-startup>1</load-on-startup>
    </servlet>




0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Application Servers

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.