File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes my first servlet please help. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "my first servlet please help." Watch "my first servlet please help." New topic
Author

my first servlet please help.

northfield Sid
Ranch Hand

Joined: Aug 08, 2002
Posts: 106
Here is my very first servlet.
I have compiled the servlet at this location:
D:\tomcat\jakarta-tomcat-3.3.1\webapps\myJSPs\jsp\Whitehead\chap11
So thus in the directory there is two files:
ServletOKlogin.java
ServletOKlogin.class
I have then created A WEB-INF folders inside chap11 and then another inside WEB-INF called classes. Inside this folder I have put the file ServletOKlogin.class, here is the path:
D:\tomcat\jakarta-tomcat-3.3.1\webapps\myJSPs\jsp\Whitehead\chap11\web-inf\classes

Below is the very simple servlet

Please not I am using Tomcat webserver
Then in the browser to execute the servlet I enter this URL in the address:
http://127.0.0.1:8080/myJSPs/jsp/Whitehead/chap11/ServletOKlogin
but I get an error:
HTTP 404 - File not found
Internet Explorer

Do I need to do anything else??
Thambi Rajah
Ranch Hand

Joined: Jul 19, 2002
Posts: 36
Hello Northfield Sid,
I did the following to test your servlet, ServletOKlogin.
(1) I have a Web Application named test; my directory structure as follows:
webapps
|
|---test
|
|---WEB-INF
|
|---classes
(2) I compiled your ServletOKlogin.class under WEB-INF/classes directory.
(3) Started the TOMCAT Server.
(4) In the browser address bar, I typed http://localhost:8080/test/servlet/ServletOKlogin
It worked fine.
Good Luck
Thambi
Thambi Rajah
Ranch Hand

Joined: Jul 19, 2002
Posts: 36
Sorry, the directory structure diagram (in my previous reply)did not show up as I typed.
The location ServletOKlogin.class is webapps/test/WEB-INF/classes.
Hope it helps.
Thambi
northfield Sid
Ranch Hand

Joined: Aug 08, 2002
Posts: 106
Okay Here is my paths:
WEB-INF\classes
Inside this folder there is one class called
ServletOKlogin.class

I have the other path
d:\tomcat\jakarta-tomcat-3.3.1\webapps\test\servlet\

In here I have two classes
ServletOKlogin.java
ServletOKlogin.class
I am accessing the servlet via the browser:
http://localhost:8080/test/servlet/ServletOKlogin
I still get the same error "HTTP 404"
Please note I am using tomcat 3.3.1
What version are you using?
I don't think it should it matter?
northfield Sid
Ranch Hand

Joined: Aug 08, 2002
Posts: 106
sorry forget the path:
Okay Here is my paths:
d:\tomcat\jakarta-tomcat-3.3.1\webapps\test\WEB-INF\classes
Inside this folder there is one class called
ServletOKlogin.class

I have the other path
d:\tomcat\jakarta-tomcat-3.3.1\webapps\test\servlet\

In here I have two classes
ServletOKlogin.java
ServletOKlogin.class
I am accessing the servlet via the browser:
http://localhost:8080/test/servlet/ServletOKlogin
I still get the same error "HTTP 404"
Please note I am using tomcat 3.3.1
What version are you using?
I don't think it should it matter?
Engin Okucu
Ranch Hand

Joined: Feb 09, 2002
Posts: 174
I tried also, it works fine.
delete your second path :
--> d:\tomcat\jakarta-tomcat-3.3.1\webapps\test\servlet\
and keep only d:\tomcat\jakarta-tomcat-3.3.1\webapps\test\WEB-INF\classes . Put in 'classes ' folder tour servlet ServletOKlogin.class
- restart Tomcat
- write as URL http://localhost:8080/test/servlet/ServletOKlogin
it must work.
northfield Sid
Ranch Hand

Joined: Aug 08, 2002
Posts: 106
>http://localhost:8080/test/servlet/ServletOKlogin
Okay so it works.
But I am a little foxed.
I have no folder called servlet inside test?
Engin Okucu
Ranch Hand

Joined: Feb 09, 2002
Posts: 174
than i'm sorry. by writing d:\tomcat\jakarta-tomcat-3.3.1\webapps\test\servlet\
I tought you had a folder called servlet.
northfield Sid
Ranch Hand

Joined: Aug 08, 2002
Posts: 106
>than i'm sorry. by writing d:\tomcat\jakarta-tomcat-3.3.1\webapps\test\servlet\
I tought you had a folder called servlet.
Now I am totally perplexed.
At present I have one path:
d:\tomcat\jakarta-tomcat-3.3.1\webapps\test\WEB-INF\classes
inside the classes folder is one clases:
ServletOKlogin.class
I access the servlet by
http://localhost:8080/test/servlet/ServeletOKlogin
I am 100% sure I have no folder called "servlet" but it "WORKS" ???
Why???
Engin Okucu
Ranch Hand

Joined: Feb 09, 2002
Posts: 174
Now i understand you hmmmm...
you don't have to put a folder called 'servlet' because your server(Tomcat) knows that you are calling a servlet by writing '/servlet/ServeletOKlogin'
the is a mapping to WEB/classes that corresponds to 'servlet'. The container do it for you...
northfield Sid
Ranch Hand

Joined: Aug 08, 2002
Posts: 106
I am trying to access the ServletOklogin from an html page.
But unable to do this.
I am not sure what the path should be:
The ServletOklogin.class is located at this path:
D:\tomcat\jakarta-tomcat-3.3.1\webapps\test\WEB-INF\classes
I have the testServlet.html under the test folder, so thus the path is:
D:\tomcat\jakarta-tomcat-3.3.1\webapps\test

What should the path be for the "action" variable in the form??
I have tried other variations like:
"test/WEB-INF/classes/ServletOKlogin"
etc.
but get the error:
HTTP 404 page cannot be found???
bernd pier
Ranch Hand

Joined: Jun 21, 2002
Posts: 30
hey
i have wrote a html page which referred to a servlet.
the action tag look like this:
<form action="http://localhost:8080/examples/servlet/Coffees4" method="get" />
it work`s.
maybe your tomcatserver is not running?
bernd
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: my first servlet please help.