This week's giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Production-Ready Serverless (Operational Best Practices) and have Yan Cui on-line!
See this thread for details.
Win a copy of Production-Ready Serverless (Operational Best Practices) this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

Compiling the servlet  RSS feed

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Prasad Charasala
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
Water proof donuts! Eat them while reading this tiny ad:
global solutions you can do at home or in your backyard
https://www.kickstarter.com/projects/paulwheaton/better-world-boo
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!