File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes deployement of a simple servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "deployement of a simple servlet" Watch "deployement of a simple servlet" New topic
Author

deployement of a simple servlet

Harsha Vardhan Madiraju
Greenhorn

Joined: Dec 19, 2003
Posts: 24
Hi all,

I have written a simple "HelloWorld" servlet with the following web.xml file



<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>HelloWorldServlet</servlet-name>
<servlet-class>HelloWorldServlet</servlet-class>
</servlet>
<</web-app>

Im using Tomcat 4.1.29. what is the url i have to give in ie to execute this servlet
I have tried the following but invain

http://localhost:8080/scwcd/HelloWorldServlet
(scwcd is folder name under webapps where the servlet class is present)

http://localhost:8080/scwcd/servlet/HelloWorldServlet


But when i add the following to web.xml
<servlet-mapping>
<servlet-name>HelloWorldServlet</servlet-name>
<url-pattern>/HelloWorldServlet</url-pattern>
</servlet-mapping>
and give the url as http://localhost:8080/scwcd/HelloWorldServlet
im able to execute the servlet

My question/doubt is it mandatory to give servlet mapping tag to execute a servlet ???
chandana sapparapu
Ranch Hand

Joined: Sep 28, 2002
Posts: 63
From the Servlet specs,

<xsd:element name="servlet-mapping"
type="j2ee:servlet-mappingType"
minOccurs="0"
maxOccurs="unbounded"/>


So, servlet-mapping is not mandatory.
chandana sapparapu
Ranch Hand

Joined: Sep 28, 2002
Posts: 63
Let me add something that I missed in my previous reply. Specs don't make it mandatory to have a servlet-mapping tag. This may be because, in your web-app, you may not need even a single servlet. For example, if all you have is JSP pages without following MVC pattern, then you don't need a servlet-mapping tag.

Sorry, this doesn't answer your question. I have to install a servlet container yet. But I guess it's mandatory to have the servlet-mapping tag to execute a servlet.
Raju Sri
Ranch Hand

Joined: Mar 10, 2004
Posts: 108
Hi chandana,

I am trying like below in tomcat 5.0.25 without url-mapping. But I am not able to call the servlet .
######################################################
<?xml version="1.0" encoding="ISO-8859-1"?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<servlet>
<servlet-name>HiWorld</servlet-name>
<servlet-class>com.test.HiWorld</servlet-class>
</servlet>
</web-app>
###################################################

Can you tell me how to call the servlet without url mapping defined in web.xml ?

Cheers


SCJP 1.4<br />SCWCD 1.4<br />SCBCD 1.3<br />SCDJWS 1.4
Alessandro Danesi
Greenhorn

Joined: May 03, 2004
Posts: 3
With Tomcat I think that you can call the servlet without the servlet-mapping tag as:
http://localhost:8080/scwcd/servlet/HelloWorldServlet

if in the tomcat's web.xml (...../conf/web.xml) the servlet-mapping called invoker isn't commented.


- Alex Danesi - SCJP 1.4
Maria Lepschy
Ranch Hand

Joined: Jan 12, 2004
Posts: 78
Hi,
I have the same problem with servlets. I am using Tomcat 5.0.25.
I can start a jsp, but not a simple servlet. I have used the default directory ..\webapps\ROOT\WEB-INF\classes and I put the HelloServlet.java and HelloServlet.class.
By calling:
http://localhost:8080/servlet/HelloServlet, I receive the error:
"The requested resource (/servlet/HelloServlet) is not available."

In the system properties I have a new variable CATALINA_HOME and I set it in the path. I added to the classpath the servlet-api.jar.
I hope, somebody knows was is wrong.

Thank you in advance,
Maria
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: deployement of a simple servlet