• 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
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Basic Servlet Problem

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();
}
}
 
Ranch Hand
Posts: 297
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 297
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. I worked it out, by moving my class files to the root directory, rather than the servlets directory.
Thanks for your suggestions.
-Hemanth
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic