Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > jakarta-tomcat

jakarta-tomcat
Thread Tools
Forum Regular
Join Date: Jul 2000
Location: Jersey City, NJ 07304
Status: Offline
Reply With Quote
Nov 21, 2000, 04:06 PM
 
Let's talk tomcat. I've got it running. And I've figured out how to set my CLASSPATH using csh.cshrc. And I have my servlets running there now. (mm.mysql2.01 also works so I'm talking with a remote MySQL server)
But I'd like to create alias's. i.e. I would like http://localhost:8080/hello to go directly to: http://localhost:8080/servlet/HelloWorld

I've tried using a <context> in the server.xml file. But my browser tries to download the class file instead of executing it.

How do I do this?
     
Forum Regular
Join Date: Jul 2000
Location: Jersey City, NJ 07304
Status: Offline
Reply With Quote
Nov 21, 2000, 05:13 PM
 
OK, to answer my own question. Here's how to create an alias (or servlet-mapping) i.e. how to map a URI to a specific servlet in Tomcat:
open the file: [tomcatfolder]/webapps/ROOT/WEB-INF/web.xml
for each mapping use the xml:
<servlet-mapping>
<servlet-name>YourServlet</servlet-name>
<url-pattern>/yourURI</url-pattern>
</servlet-mapping>
inside the <web-app> tags
restart Tomcat.

I found this site VERY helpful and I really appreciate that this Perl programmer created an web page to search the Tomcat discussion list archives: http://www.metronet.com/~wjm/tomcat/

- miles
     
jhh
Guest
Status:
Reply With Quote
Nov 22, 2000, 08:39 AM
 
I think you should add a Context tag in conf/server.xml
something like:
<Context docBase="mystuff" path="/mystuff"
reloadable="false" trusted="true">
</Context>

then do your servlet-mapping in webapps/mystuff/WEB-INF/web.xml

jhh
     
Forum Regular
Join Date: Jul 2000
Location: Jersey City, NJ 07304
Status: Offline
Reply With Quote
Nov 22, 2000, 11:21 PM
 
Maybe you're right, since my solution doesn't quite work like I need it too. with the current set-up, a link like www.mysite.com/hello goes to my HelloWorld servlet, as mapped. However, when I try to pass a param like this: www.mysite.com/hello/param, then it doesn't work, and thinks its a different URI. So I tried, in web.xml, a mapping like this:
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/hello/*</url-pattern>
</servlet-mapping>
but it doesn't work.
the mappings in server.xml seem to point to real directories in Tomcat's folder. But how to make one that points to the servlet execution engine, like I assume /servlet points to this engine.

- miles
     
jhh
Guest
Status:
Reply With Quote
Nov 23, 2000, 09:52 AM
 
"I feel your pain"
Things are not working too well for me either. There seems to be a huge lack of understandable documentation...
You could try mapping to "/" in your web.xml
<web-app>
<servlet>
<servlet-name>HelloWorld<servlet-name>
<servlet-class>where.ever.HelloWorld<servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>

In my case something in the config is causing an infinite redirect loop which, while fun to watch, is not the right behavior.
I've had to modify bin/catalina.sh to add classes to the classpath and conf/server.xml to add Contexts and then the associated webapp web.xml for servlet definition.
One thing that confuses me is the WEB-INF directory - why is it there?
jhh


     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 12:46 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2