• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

Custom WebApp servlet url problem

 
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all ,

I am new to this so if this is a stupid question don't hate me too much. Btw I am using Tomcat 5.5.9. I created a custom WebApp by copying and renaming the ROOT dir in Tomcats WebApps dir. I can hit pages and servlets by usig the url
host/myWebApp/my.html and host/myWebApp/servlet.package.myservlet fine.
My problem is when I try to use a relative url. For example if I am trying to call a
servlet from an html page it seems to add the webApp name twice to the url. For example if I have a html page that calls a servlet like
<A HREF="myWebApp/servlet/mypackage.myservlet"></A> when you hover over the link, the url that is built is host/myWebApp/myWebApp/servlet/mypackage.myservlet. Why does it add the webAppName twice? I can't figure it out.

Thanks,

Jutah.
 
Rancher
Posts: 43024
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The page containing the link is presumably part of myWebApp, so its URL is "host/myWebApp/xyz.html". If you create a URL relative to that which starts with "myWebApp/...", it gets appended to the base URL of the current page, which already has the myWebApp part. Hence, myWebApp gets included twice.
 
Andrew Mcmurray
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, so I should do something like ../myWebApp/servlet/mypackage.myservlet

Jutah
 
Andrew Mcmurray
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I am still alittle confused. I the html page is in webapps/myWebApp/
and my url to the servlet then /servlet/mypackage.myservlet. If I do this then the myWebApp gets cut out of the url. So the url reads host/servlet/mypackage.myservlet. Why does it drop my webApp name if that is the dir the html page is in?

Thanks,

Jutah
 
Marshal
Posts: 67515
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

so I should do something like ../myWebApp/servlet/mypackage.myservlet



No. You should not be using relative URLs at all. Your webapp references should all be made prefixed with /myWevApp.

The leading / is significant.

Also, I notice that you are using the servlet invoker. You should read this.
[ September 24, 2005: Message edited by: Bear Bibeault ]
 
Andrew Mcmurray
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks! It worked useing the /. Also thanks for the link on the web.xml I will give that a try now.

Jutah
 
Andrew Mcmurray
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I tried adding my own web.xml, but now I can't access any html pages. I copied the default one put it in webapps\myWebApp\WEB-INF. I only added one servlet and a mapping. Did I have to add any attributes to the <web-app> tag? I also stopped and restarted the server after modifing the file. Any thoughts?

Thanks again,

Jutah
 
Ulf Dittmer
Rancher
Posts: 43024
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The default web.xml maps the servlet to "/", which catches all requests, HTML pages included. Change that to "/myservlet" or whatever URL you want your servlet to respond to, and it should work.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by John Utah:
Ok, I tried adding my own web.xml, but now I can't access any html pages. I copied the default one put it in webapps\myWebApp\WEB-INF. I only added one servlet and a mapping. Did I have to add any attributes to the <web-app> tag? I also stopped and restarted the server after modifing the file. Any thoughts?

Thanks again,

Jutah



If you would like a small, working example, download SimpleServlet.war from:
http://simple.souther.us and drop it in your TOMCAT_HOME/webapps directory.

It's just a 'Hello, World' servlet app with proper mappings.
 
Andrew Mcmurray
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great! Thanks, I'll give those a try

jutah
 
ranger
Posts: 17346
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You know there was a character in "Point Break" called Johnnie Utah. By any chance are your parents big fans of that movie?

Mark
 
You learn how to close your eyes and tell yourself "this just isn't really happening to me." Tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic