• 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
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

SimpleServlet.java:2: package javax.servlet does not exist

 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai friends,

I am getting some error when i am compileing my servlet
Please resolve it

SimpleServlet.java:2: package javax.servlet does not exist
import javax.servlet.*;

i cluded servelet-api.jar in my classpath even though i am getting this error

Thanks in advance
Suma
 
Marshal
Posts: 67275
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by sumaraghavi ragha:

i cluded servelet-api.jar in my classpath even though i am getting this error



Easy one. You mis-spelled the name of the jar file. it's servlet-api.jar.
 
sumaraghavi ragha
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai

Sorry i gave the correct name in class path
i.e servlet-api.jar

even though it's not working

Thanks
 
sumaraghavi ragha
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai
My directory structure is like this

C:\apache-tomcat-5.5.20\webapps\library\WEB-INF\src

in this i had a class called
LibServlet

the code is
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class LibServlet extends HttpServlet

{
public void init(ServletConfig config)throws ServletException
{
System.out.println(" in library servlet!!!");
super.init(config);

}

public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException
{
doPost(request,response);
}
public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException
{

response.setContentType("text/html");
PrintWriter out = response.getWriter();


out.println("<html>");
out.println("<head><title>Library</title></head>");
out.println("<body>");
out.println("<table>");

out.println("<tr>");
out.println("<td>");
out.println("you have successfully loged in");
out.println("</td>");
out.println("</tr>");


out.println("<tr>");
out.println("<td>");
out.println("<select>");
out.println("<option>science</option>");
out.println("<option>general</option>");
out.println("<option>movies</option>");
out.println("</select>");
out.println("</td>");
out.println("</tr>");

out.println("</table>");
out.println("<body></html>");
out.close();
}
and html pages are like this

Directory
C:\apache-tomcat-5.5.20\webapps\library\html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Servlet</TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>

<BODY>
<form action="../servlet/LibServlet" >
<table bgcolor='red'>

<table align=center>
<tr>
<td valign=top width=400 height=70 ><B> Welcome to UMA library</B>
</td>
</tr>
</table>
<table>
<tr>
<td>Name: </td>
<td>
<input type="text"
name="name">
</td>
</tr>
<tr>
<td>Password: </td>
<td>
<input type="password"
name="password">
</td>
</tr>
<tr>
<td colspan=2>
<input type="submit"
name="submit" value="submitform" >

</td>
</tr>
</table>
</table>
</form>


</BODY>
</HTML>



</BODY>
</HTML>


and classpath is
C:\Program Files\Java\jdk1.5.0_07\bin;C:\Program Files\Apache Software Foundation\Tomcat 5.5\common\lib\servlet-api.jar


and errors are

C:\Program Files\Java\jdk1.5.0_07\bin>
C:\Program Files\Java\jdk1.5.0_07\bin>javac LibServlet.java
LibServlet.java:2: package javax.servlet does not exist
import javax.servlet.*;
^
LibServlet.java:3: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
LibServlet.java:7: cannot find symbol
symbol: class HttpServlet
public class LibServlet extends HttpServlet
^
LibServlet.java:10: cannot find symbol
symbol : class ServletConfig
location: class LibServlet
public void init(ServletConfig config)throws ServletException
^
LibServlet.java:10: cannot find symbol
symbol : class ServletException
location: class LibServlet
public void init(ServletConfig config)throws ServletException
^
LibServlet.java:17: cannot find symbol
symbol : class HttpServletRequest
location: class LibServlet
public void doGet(HttpServletRequest request,HttpServletResponse respons
e)throws ServletException,IOException
^
LibServlet.java:17: cannot find symbol
symbol : class HttpServletResponse
location: class LibServlet
public void doGet(HttpServletRequest request,HttpServletResponse respons
e)throws ServletException,IOException
^
LibServlet.java:17: cannot find symbol
symbol : class ServletException
location: class LibServlet
public void doGet(HttpServletRequest request,HttpServletResponse respons
e)throws ServletException,IOException

^
LibServlet.java:21: cannot find symbol
symbol : class HttpServletRequest
location: class LibServlet
public void doPost(HttpServletRequest request,HttpServletResponse respon
se)throws ServletException,IOException
^
LibServlet.java:21: cannot find symbol
symbol : class HttpServletResponse
location: class LibServlet
public void doPost(HttpServletRequest request,HttpServletResponse respon
se)throws ServletException,IOException
^
LibServlet.java:21: cannot find symbol
symbol : class ServletException
location: class LibServlet
public void doPost(HttpServletRequest request,HttpServletResponse respon
se)throws ServletException,IOException


please helpme out

Thanks in advance
^
LibServlet.java:13: cannot find symbol
symbol : variable super
location: class LibServlet
super.init(config);
^
12 errors

C:\Program Files\Java\jdk1.5.0_07\bin>
 
Bear Bibeault
Marshal
Posts: 67275
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by sumaraghavi ragha:

Sorry i gave the correct name in class path
i.e servlet-api.jar

Please read this
[ February 08, 2007: Message edited by: Bear Bibeault ]
 
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no boss i have compiled your code only.it is working fine after servlet-api.jar is added to classpath.
you should try to run set command from the directory from where you are compiling means from directory C:\Program Files\Java\jdk1.5.0_07\bin set
It will show you classpath,if servlet-api is present there,kindly check this jar file and check whether javax.servlet package is present in this jar file.
It still not able to do ,let me know.
 
Raj Kumar Bindal
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no boss i have compiled your code only.it is working fine after servlet-api.jar is added to classpath.
you should try to run set command from the directory from where you are compiling means from directory C:\Program Files\Java\jdk1.5.0_07\bin set
It will show you classpath,if servlet-api is present there,kindly check this jar file and check whether javax.servlet package is present in this jar file.
It still not able to do ,let me know.
 
Ranch Hand
Posts: 1325
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cannot find Symbol: means you are using a class name that the compiler doesn't recognize or cannot find any resource to understand it.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!