aspose file tools*
The moose likes Servlets and the fly likes Compiling the servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Compiling the servlet" Watch "Compiling the servlet" New topic
Author

Compiling the servlet

Chitra Sundaram
Greenhorn

Joined: Oct 24, 2000
Posts: 18
I have downloaded JSDK 2.1 and have written a simple servlet. I am unable to compile this. It gives me a compiler error as follows:
C:\JavaAssg\SimpleServlet.java:1: cannot resolve symbol
symbol : class HttpServlet
location: class SimpleServlet
public class SimpleServlet extends HttpServlet{

and more
which indicates to me that it is unable to find the class HttpServlet. I already have c:\jsdk2.1\server.jar, c:\jsdk2.1\servlet.jar and c:\jsdk2.1\src in my classpath.
Can somebody please help me??

And also... which directory should the servlets.properties file be placed in?
Thanks
Chitra
Prasad Charasala
Ranch Hand

Joined: Nov 02, 2000
Posts: 67
Hi Chitra,
The servlets.properties file must be under yourJSDKfolder/webpages/web-inf.
If you have unzipped the downloaded zip file it will place all the files appropriately.
Send me your servlet code (charasala@yahoo.com), I will fix it and send it back to you.
------------------
Prasad


<B>Prasad</B>
Prasad Charasala
Ranch Hand

Joined: Nov 02, 2000
Posts: 67
Hi Chitra,
The code is perfectly correct except it is missing import statements. I ran it on my machine it perfectly works. The code should have the three import statements. Follow the following steps to run it.
1. Make sure your classpath has c:\Jsdk2.1\server.jar;c:\Jsdk2.1\servlet.jar.
2. Put the source code in c:\Jsdk2.1\webpages\web-inf\servlets folder.
3. Compile it and make sure your generated class file is in the same servlets folder.
4. You have a servlets.properties file under c:\Jsdk2.1\webpages\web-inf. make sure to add the following line
simple.code=SimpleServlet
5. Save the properties file. go to c:\Jsdk2.1 folder and start the server.
6. Now try this url from your browser
http://localhost:8080/servlet/simple or http://localhost:8080/servlet/SimpleServlet
It must work. Please note there is no 's' in the url. It is not 'servlets', only 'servlet'.
<code>
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class SimpleServlet extends HttpServlet{
public void doGet( HttpServletRequest request,
HttpServletResponse
response)
throws ServletException, IOException
{
PrintWriter out;
String title="Simple Servlet Output";
response.setContentType("text/html");
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();
}
}
</code>

------------------
Prasad
[This message has been edited by Prasad Charasala (edited November 07, 2000).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Compiling the servlet