• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

tomcat newbie

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hie there..

i am new to JSP and tomcat...
what i understand about JSP is it used to display the output while the servlet will do the processing.

Here is basically what i wanna implement in my web application..

user->JSP(form)->pass the value to servlet(.java)->processing value(servlet)->pass the output to JSP->display out(JSP).

i know that all JSP files should put in ../tomcat/webapps/ROOT/
but how about the servlet?...i tried putting it in ../ROOT/WEB-INF/classes
but it gives me errors...

i check in Internet..and most of them told me that i should set the classpath of the servlet the i wanna use..i tried but still give me errors.

anyone?
 
Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The servlet goes into WEB-INF/classes.
No need to tinker with the classpath.
Basically, it your servlet is called "pack.MyServlet" (where "pack" is the package name), try the following:

1. Compile the servlet and put it into "classes", so that you get:
WEB-INF/classes/pack/MyServlet.class
(Pitfalls: make sure to maintain the "pack" directory, and also note that it's the compiled ".class", not the ".java" source).

2. Locate the file "WEB-INF/web.xml" , and add a "servlet-mapping" to it.
A simple "web.xml" looks like:


In your case, if you use the existing ROOT, you'll need to add those entries to the existing web.xml, which already has some entries.
Just note the order: first all "servelt" tags, then all "servlet-mappings", so it'll be something like:
< servlet > ...
< servlet > ...
< servlet-mapping > ...
< servlet-mapping > ...


3. Start up tomcat (to be on the safe side, make sure Tomcat's not running while you do the above changes. Start it only after everything's ready. It's an overkill, but it'll do for starters).

4. Point you browser to:
http://localhost:8080/MyServlet

Hope this helps... if not, could you please quote the exact error message issued by tomcat ?
 
Yong Ming Wai
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for advice...

After few changes..i managed to get it done.
Unfortunately,new problems arise along..
My system has alot of folders which contain lots of servlets..(.class)
do i have to declare all of them and map it in web.xml one by one..

examples:

my login.jsp will post value to login.class(login folder) which will import util.class(in system folder) to use DCconnect() to verify the login..then..if valid..
login.class will call welcome.jsp

do i have to..
write...
< servlet > ...
< servlet > ...
< servlet-mapping > ...
< servlet-mapping > ... for all the servlet?
if kinda of troublesome,rite?
 
Sol Mayer-Orn
Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good question...
I know of 2 workarounds for it (but there could be more):

1. Tomcat is supposed to have an "invoker servlet".
Haven't used it much, but you should be allowed to add the following to "web.xml":


You'll probably find it ugly (lots of if's inside the servlet, and no obvious gain), but it's worth mentioning since that's the idea behind the popular Struts framework (of course, Struts is much smarter than a bunch of silly if's... on the other hand, it still makes you do lots of XML configuration).

Good luck
 
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
I wouldn't steer new users into the using the invoker servlet.
It's been deprecated for a a reason. See: http://faq.javaranch.com/view?InvokerServlet

It's own creators call it evil: http://jakarta.apache.org/tomcat/faq/misc.html#evil

Take the time to map your servlets. It only needs to be done once for each servlet and the benefits far outweigh the hassle of doing so.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic