You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Nicola Galante <ni...@pd.infn.it> on 2003/01/14 16:28:48 UTC

servlet with Tomcat

I will expose you a problem I found with Tomcat 4.1.18 but first is 
better if I describe to you what's happened. System administrators of my 
department installed J2SDK 1.4.1 and Tomcat 4.1.18 in a local machine. 
After that I have setted the enviroment variables CATALINA_HOME to the 
install_dir of Tomcat and JAVA_HOME to the install_dir of J2SDK1.4.1 
classes. Then I can start Tomcat using the script 
$CATALINA_HOME/bin/startup.sh (it is a Linux machine) and I can see the 
local home page
$CATALINA_HOME/webapp/ROOT/index.html
browsing http://localhost:8080/ .
I can see aslo the example servlets situated at 
$CATALINA_HOME/webapp/examples/WEB-INF/classes/  browsing 
http://localhost:8080/examples/servlet/ServletName
but I cannot see servlets situated in the usual work directory
$CATALINA_HOME/webapp/ROOT/WEB-INF/classes
browsing http://localhost:8080/servlet/ServletName
(I'm just a beginner of JSP technology and this is what I found in a JSP 
manual that I should do). I mean that if I create any my servlet file 
called MyServlet.class and I put it in the directory
$CATALINA_HOME/webapp/examples/WEB-INF/classes/
I can see it, but I canno see it If I put it in the directory
$CATALINA_HOME/webapp/ROOT/WEB-INF/classes.
I can also tell you that I can see any html page situated at
$CATALINA_HOME/webapp/ROOT/MyPage.html
browsing http://localhost:8080/MyPage.html

Do you think this is a problem of configuration of Tomcat? How can I 
have a dedicated directory for my servlet classes?

I send to you this mail because I'm just a beginner of servlets and 
Tomcat, and system administrators of my department told me that they 
never used Tonmcat before now, so they cannot (or they don't want to) 
help me.

I would be very please to you if someone of you could help me.

Thanks

Nicola

-- 
-------------------------------------------
Nicola Galante
Universita' degli studi di Siena -- ITALY
Tel. (PD) (+39) 049 827 7214
e-mail: nicola.galante@pd.infn.it
-------------------------------------------



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: servlet with Tomcat

Posted by "Noel J. Bergman" <no...@devtech.com>.
Steve,

> Are you able to view any of the supplied examples successfully
> that came with the Tomcat installation of yours'???! I can see
> the code easily enough, BUT I cannot seem to see the actual
> servlets at all!

Are you saying that Tomcat is running standalone, but if you go to the
sample servlets, they are not working?

> any advice that you might have on using the <servlet-mapping>
> tag that's in the web.xml file

The servlet mapping takes two things: the name of the servlet, which was
specified in a servlet tag earlier, and a URL relative to that webapp.

But if tomcat isn't working, for some reason, with the servlets that come
with it, then you are effectivel chasing phantoms trying to make your own
servlets work.  First you need to make sure that tomcat is running properly
on your system.

	--- Noel


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: servlet with Tomcat

Posted by Peter Harrison <pe...@asterisk.co.nz>.
On Wed, 15 Jan 2003 09:57, Steve R Burrus wrote:
>  Nicole, that's really fine and good that you bothered to send me a web
> page that purportedly offers me some free advice on how the hell I go about
> seeing/viewing a compiled servlet, BUT I really thought that you could, if
> you would please, directly give some help on editing that web.xml file!

There are a number of good sources for information. The Servlet API 2.3 
specification provides the official standard for the XML web application 
configuration descriptor - web.xml. The tomcat documentation itself provides 
a pretty reasonable overview. Finally you might consider purchasing a book on 
the subject.

Regards,

Peter Harrison

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: servlet with Tomcat

Posted by "Noel J. Bergman" <no...@devtech.com>.
> Be careful what you wish for Mr. Burrus, you just may get it.

Now, now, guys ... play nice.

Actually, I sent him his entire sample app in a .ZIP file after making sure
that it worked in tomcat for me.

	--- Noel


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: servlet with Tomcat

Posted by Will Hartung <wi...@msoft.com>.
> From: "Steve R Burrus" <bu...@yahoo.com>
> Sent: Tuesday, January 14, 2003 12:57 PM
> Subject: RE: servlet with Tomcat


> Nicole, that's really fine and good that you bothered to send me a web
page that
> purportedly offers me some free advice on how the hell I go about
seeing/viewing a
> compiled servlet, BUT I really thought that you could, if you would
please,
> directly give some help on editing that web.xml file!

Be careful what you wish for Mr. Burrus, you just may get it.

0. Format your system and install a recent release of Windows 2000(this step
is optional -- although I'm afraid it may not be for you)

1. Download J2SE SDK for Windows
(http://java.sun.com/j2se/1.3/download.html), and install it. Place it in
C:\JDK1.3.1 when it asks for a destination. This is JAVA_HOME

2. Download latest binary of Tomcat
(http://jakarta.apache.org/builds/jakarta-tomcat-4.0/release/v4.1.18/bin/jak
arta-tomcat-4.1.18.zip). Unzip this at C:, and it creates
C:\jakarta-tomcat-4.1.18. This is CATALINA_HOME

3. Download and install from http://www.cygwin.com/setup.exe. (You need this
to use the vi editor later on). Install in in C:\CYGWIN

3. Open a DOS Command Prompt

4. Type: SET JAVA_HOME=C:\JDK1.3.1

5 Type: SET PATH=%PATH%;C:\CYGWIN\BIN;%JAVA_HOME%\BIN

6 Type: SET CATALINA_HOME=C:\jakarta-tomcat-4.1.18

7 Type: CD %CATALINA_HOME%\webapps\examples\WEB-INF\classes

8. Create a new file here: HelloSteve.java, and place the following code in
it. Note that <ENTER> and <ESC> are the actual ENTER key and ESC keys on
your keyboard.
Type: vi HelloSteve.java
i (to enter insert mode in vi)
import java.io.*;<ENTER>
import java.text.*;<ENTER>
import java.util.*;<ENTER>
import javax.servlet.*;<ENTER>
import javax.servlet.http.*;<ENTER>
<ENTER>
public class HelloSteve extends HttpServlet {<ENTER>
    public void doGet(HttpServletRequest request,<ENTER>
                      HttpServletResponse response)<ENTER>
        throws IOException, ServletException<ENTER>
    {<ENTER>
        response.setContentType("text/html");<ENTER>
        PrintWriter out = response.getWriter();<ENTER>
<ENTER>
        out.println("<html>");<ENTER>
        out.println("<head>");<ENTER>
        out.println("<title>Hi! My name is Steve!</title>");<ENTER>
        out.println("</head>");<ENTER>
        out.println("<body>");<ENTER>
        out.println("<B>Hi! My name is Steve Burrus!</B><br>");<ENTER>
        out.println("I tend to be <i>abusive, ignorant, and
untrainable.</i><br>");<ENTER>
        out.println("I appear to suffer from docuphobia, a distinct
affliction that prevents me from");<ENTER>
        out.println("reading documentation<br>");<ENTER>
        out.println("</body>");<ENTER>
        out.println("</html>");<ENTER>
    }<ENTER>
}<ENTER>
<ESC>:wq!

9. Type: javac -classpath %CATALINA_HOME%\common\lib\servlet.jar
HelloSteve.java

10. Ok, here's the crown jewels. "Direct help" on editing web.xml. Now, I'm
using the vi editor here, again, because it's the easiet one to follow along
with. So, stay close and do what I do exactly.

Type: cd .. (this takes you to %CATALINA_HOME\webapps\examples\WEB-INF)
Type: vi web.xml<ENTER>
/<servlet><ENTER>
4yyP8wcwHelloSteve<ESC>
11wcwHelloSteve<ESC>
/let-map<ENTER>
4yyP10wcwHelloSteve<ESC>
11whxdwxxi/HelloSteve<ESC>
:wq!<ENTER>

Ok, now you've changed the web.xml file.

Type: cd ..\..\..\bin (gets you to the bin directory for tomcat)
Type: catalina.bat run (starts tomcat in your shells window) Let Tomcat
start up. Wait for this line:
[INFO] Http11Protocol - -Starting Coyote HTTP/1.1 on port 8080

Now, open a browser and use this URL:
http://localhost:8080/examples/HelloSteve

There ya go, your own servlet.

Everything you asked for. It really can not get any more detailed than this.
Truly. Just follow along VERY CAREFULLY and this will work just peachy.

HTH

Regards,

Will Hartung
(willh@msoft.com)




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: servlet with Tomcat

Posted by Steve R Burrus <bu...@yahoo.com>.
 No, I am very definitely NOT a "newbie" to manners, whoever you are!! "Are you a
newbie to tomcat or a newbie to manners, Steve?" I just simply wanted for someone
to tell me how exactly I go about editing the web.xml file so I can then see/view
a servlet in my browser! If that offends anyone (and I don't see how it possibly
could), then I am sorry!! 

__________________________________________________
Do you Yahoo!?
Yahoo! News - Today's headlines
http://news.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: servlet with Tomcat

Posted by mech <me...@rz.fh-augsburg.de>.
Are you a newbie to tomcat or a newbie to manners, Steve?
Maybe start working on something else... I guess you'll find it
difficult to get any help from anyone on this list after insulting
posters.

> -----Original Message-----
> From: Steve R Burrus [mailto:burrus21@yahoo.com] 
> Sent: Dienstag, 14. Januar 2003 21:57
> To: Tomcat Users List
> Subject: RE: servlet with Tomcat
> 
> 
>  Nicole, that's really fine and good that you bothered to 
> send me a web page that purportedly offers me some free 
> advice on how the hell I go about seeing/viewing a compiled 
> servlet, BUT I really thought that you could, if you would 
> please, directly give some help on editing that web.xml file!
> 
> __________________________________________________
> Do you Yahoo!?
> Yahoo! Mail Plus - Powerful. Affordable. Sign up now. 
http://mailplus.yahoo.com

--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: servlet with Tomcat

Posted by Steve R Burrus <bu...@yahoo.com>.
 Nicole, that's really fine and good that you bothered to send me a web page that
purportedly offers me some free advice on how the hell I go about seeing/viewing a
compiled servlet, BUT I really thought that you could, if you would please,
directly give some help on editing that web.xml file!

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: servlet with Tomcat

Posted by Nicole Hibbard <nh...@xtelesis.com>.
I am a newbie and used this page to help my in seeing examples and creating
my own servlets.  I hope that it helps.

http://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/



-----Original Message-----
From: Steve R Burrus [mailto:burrus21@yahoo.com]
Sent: Tuesday, January 14, 2003 11:48 AM
To: Tomcat Users List
Subject: Re: servlet with Tomcat


 Nicola, even though you seem to communicate in some "broken" English, I can
still
understand the "gist" of what you said in your post, that you are
encountering
some trouble/problems with trying to see either a servlet or a JSP in your
web
browser!!

 I wanna tell u that I am having the very same problems myself, and that I
am also
quite a "newbie" at trying to Tomcat to see the servlets/jsp's. Are you able
to
view any of the supplied examples successfully that came with the Tomcat
installation of yours'???! I can see the code easily enough, BUT I cannot
seem to
see the actual servlets at all! Now whassssssssup with that anyway? Can you
please
"point me in the right direction" as far as seeing these servlet examples
goes? It
would be like one "newbie" [you] helping out another "newbie" [me], but
that's OK
in the whole grand scheme of things :) And if you could also "throw in", for
my
benefit, any advice that you might have on using the <servlet-mapping> tag
that's
in the web.xml file, as u know. I am still having all kinds of problems with
editing that file. What should be specified for the <servlet-name> and the
<servlet-class> tags? Thanx in advance.

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: servlet with Tomcat

Posted by Steve R Burrus <bu...@yahoo.com>.
 Nicola, even though you seem to communicate in some "broken" English, I can still
understand the "gist" of what you said in your post, that you are encountering
some trouble/problems with trying to see either a servlet or a JSP in your web
browser!!

 I wanna tell u that I am having the very same problems myself, and that I am also
quite a "newbie" at trying to Tomcat to see the servlets/jsp's. Are you able to
view any of the supplied examples successfully that came with the Tomcat
installation of yours'???! I can see the code easily enough, BUT I cannot seem to
see the actual servlets at all! Now whassssssssup with that anyway? Can you please
"point me in the right direction" as far as seeing these servlet examples goes? It
would be like one "newbie" [you] helping out another "newbie" [me], but that's OK
in the whole grand scheme of things :) And if you could also "throw in", for my
benefit, any advice that you might have on using the <servlet-mapping> tag that's
in the web.xml file, as u know. I am still having all kinds of problems with
editing that file. What should be specified for the <servlet-name> and the
<servlet-class> tags? Thanx in advance.  

__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>