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

calling servlet

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

I successfully load the application(starting file = index.html) when i run tomcat 4 and enter the Url. But i am unable to call the servelt from index.html. What should be the solutions in following?

- Calling from a hyperlink.
- Can i call it by using 'Form' or something like 'Action' from html file.
- Is servlet-mapping necessary in above two cases. If yes then should i call the actual class or mapping class name.Plz insert a line or two of html code as an example.

Assuming the classes are in directory WEB-INF/Classes/Classes/

I have tried in various patterns but it returns error no. 404 while i can successfully load and run the servlets if i call it directly from Url wihtout using index.html.

Thnx in advance.
Naveed
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well,
when calling servlet use
./servlet/servletpackage.servletname

for example if your servlet is in sun.com package
and its name is ExampleServlet
you should call it
./servlet/sun.com.ExampleServlet

all servlet classes should be placed in web-inf/classes/
directory
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

/servlet/servletpackage.servletname


No no no no - do NOT use the invoker servlet (implied by /servlet/) - it isn't even turned on in Tomcat 4 on. See the invoker servlet FAQ here at the ranchhouse.
Nothing but confusion can come of relying on the invoker servlet to address a servlet.
Bill
 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Assuming the classes are in directory WEB-INF/Classes/Classes/



First of all you must store the class files under WEB-INF/classes and try invoking the servlet using any of the standard procedure.

Secondy, according to your WEB-INF directory structure the Classes directory under /Classes will be treated as a package path.

for example,

package Example;

{
your class definitions
}

the dir structure should be WEB-INF/classes/Example/<your class file> and you must invoke the servlet using the package name.servletname.

the dd format is as follws.

<servlet>
<servlet-name>example</servlet-name>
<servlet-class>ExampleServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>example<servlet-name>
<url-pattern>/servlet/ExampleServlet</url-pattern>
</servlet-mapping>

hope this helps.

regards,
ravi.
[ June 15, 2004: Message edited by: Ravikumar Jambunathan ]
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you point to a good doc on the xml configuration you showed? I've seen several examples and have one or two up & running in Tomcat/Eclipse but the entries don't make sense to me yet. Thanks!
 
Ravikumar Jambunathan
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi james,

hope you have misunderstood. I have given only the <servlet> and <servlet-mapping> portion as an example. I presume, you have misunderstood because of the sentence "dd format". I did not mean the web.xml format.

hope it is clear now.

regards,
ravi.
 
Naveed Ali
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well, i have just missed one point that i have created new application by creating new directory 'application' under the 'webapps\ROOt\' dir. I have given the context path as '/application'. So the exact directory structure in my case is ROOT/application/classes/classes and not the previous one i had given. The WEB-INF dir is under the 'application' dir. I have packaged my servlet class in package named 'classes'. Here i am posting the mapping.

<servlet>
<servlet-name>Helloservlet2</servlet-name>
<servlet-class>classes.servlet2</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>Helloservlet2<servlet-name>
<url-pattern>/classes/classes/Helloservlet2</url-pattern>
</servlet-mapping>

i had given '/classes/classes/Helloservlet2' in the hyperlink which gave me error 404.

regards

naveed
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, webapps\ROOT is already a web application - it has a WEB-INF and web.xml etc.
You can't create another web application under ROOT, you must create it under webapps. Assuming your application name is application and your servlet is in the "classes" package and the servlet class name is indeed "servlet2" like it says in your web.xml, your directory structure should be:


For documentation of how to fix your web.xml - why not go to the source?
http://java.sun.com/products/servlet/reference/api/index.html
and
http://java.sun.com/products/jsp/reference/api/index.html

Bill

[ June 15, 2004: Message edited by: William Brogden ]
[ June 15, 2004: Message edited by: William Brogden ]
 
CLUCK LIKE A CHICKEN! Now look at this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic