wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes SimpleServlet.java:2: package javax.servlet does not exist Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "SimpleServlet.java:2: package javax.servlet does not exist" Watch "SimpleServlet.java:2: package javax.servlet does not exist" New topic
Author

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

sumaraghavi ragha
Ranch Hand

Joined: Nov 17, 2006
Posts: 118
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
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
sumaraghavi ragha
Ranch Hand

Joined: Nov 17, 2006
Posts: 118
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

Joined: Nov 17, 2006
Posts: 118
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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

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 ]
Raj Kumar Bindal
Ranch Hand

Joined: Apr 15, 2006
Posts: 417
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

Joined: Apr 15, 2006
Posts: 417
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.
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

cannot find Symbol: means you are using a class name that the compiler doesn't recognize or cannot find any resource to understand it.


Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SimpleServlet.java:2: package javax.servlet does not exist
 
Similar Threads
JCreator help !!!
Need help urgently: problems compiling servlets
servlet compilation error.
error in compiling - package does not exist
Servlet Compilation Error