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 Basic Servlet Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Basic Servlet Problem" Watch "Basic Servlet Problem" New topic
Author

Basic Servlet Problem

Hemanth Presingu
Ranch Hand

Joined: Oct 01, 2000
Posts: 30
I am having a basic problem in running servlets. I installed JSDK2.1 and wrote a basic servlet.
The code is from Suns' website. When i run the servlet by entering the name as http://localhost:8080/basic
It gives an error - "file not found."
I also modified the servlet.properties file to add my servlet as:
basic.code=SimpleServlet
Where SimpleServlet is my servlet class.
I ran the Servlet server currently and am able to successfully run one of the example servlet in the servlet.properties file.
I am missing something basic here. Can anyone help me.
Thanks.
-Hemanth
import javax.servlet.*;
import javax.servlet.http.*;

public class SimpleServlet extends HttpServlet
{
/**
* Handle the HTTP GET method by building a simple web page.
*/
public void doGet (HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
PrintWriterout;
Stringtitle = "Simple Servlet Output";
// set content type and other response header fields first
response.setContentType("text/html");
// then write the data of the response
out = response.getWriter();
out.println("<HTML><HEAD><TITLE>");
out.println(title);
out.println("</TITLE></HEAD><BODY>");
out.println("<H1>" + title + "</H1>");
out.println("<P>This is output from SimpleServlet.");
out.println("</BODY></HTML>");
out.close();
}
}
Michael Hildner
Ranch Hand

Joined: Oct 13, 2000
Posts: 297
I'm new at this myself, so you better verify my answer, but I believe your 'basic.class' needs to be under the 'classes' subdirectory. I did a default install and the whole path is c:\jakarta-tomcat\webapps\ROOT\WEB-INF\classes.
Then your url should be http://localhost:8080/servlet/basic.
When accessing subdirectories under classes (i.e. ...\classes\MyCompany\registration\Login.class the url is http://localhost:8080/servlet/MyCompany.registration.Login
Hemanth Presingu
Ranch Hand

Joined: Oct 01, 2000
Posts: 30
I think my classes are in the correct directory. i.c /web-inf/servlets.
The example servlet, i.e. SnoopServlet class is in the same directory and i am able to run that by giving the URL
http://localhost:8080/snoop
When i specify http://localhost:8080/basic
where basic is SimpleServlet class then it gives a HTTP File not Found error.

Michael Hildner
Ranch Hand

Joined: Oct 13, 2000
Posts: 297
Sorry, didn't read you original email close enough I haven't yet modified a servlet.properties file (I don't even have one). I've just been accessing it the .../servlet/ way. Not sure why it's important to give the servlet an alias (seems cryptic enough already). Since I obviously don't know what I'm talking about, I need to research this. I will let you know here if I get it running using the servlet.properties file. Best of luck.
Rajesh Hegde
Ranch Hand

Joined: Sep 15, 2000
Posts: 112
Hey Listen, why do not u give the give this URL in the browser and see- http://localhost:8080/SimpleServlet
Thats b'coz by default, the servlet's name is the name of the class. try it out and see. Mean while i'll see the servlet.properties file approach.
Rajesh Hegde
Ranch Hand

Joined: Sep 15, 2000
Posts: 112
hey ,
Give the URL as http://localhost:8080/servlet/basic.java . It works as i checked it out.
Very small error , Hope u must have found it out by ur self.
Hemanth Presingu
Ranch Hand

Joined: Oct 01, 2000
Posts: 30
Yes. I worked it out, by moving my class files to the root directory, rather than the servlets directory.
Thanks for your suggestions.
-Hemanth
MSD
Greenhorn

Joined: Jan 22, 2000
Posts: 20
Hi Hemanth,
Well, i had the same problem when i started off. I read the readme file with the jswdk and did some r&d.
Well, i guess ur problem is that the servlet engine does not recognize ur service. What u need to do is open the webserver.xml file(located in the jswdk root dir) and add an entry for a new service that u want to run. It could be something like this :

Now this entry needs to be inside the <webserver>...</webserver> tags. The docBase entries are the directory in which u store all ur application files, it is relative to the server root. If u have already created a directory called basic, just provide it's path relative to the jswdk root in the docBase.
This should work. Now place all ur servlet class files in basic/web-inf/servlets directory. U can place all ur html files in the basic directory itself.
Hope this helps,
_Mohammed
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Basic Servlet Problem