• 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
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

package javax.servlet does not exist

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am getting when i compile this servlet program i got "package javax.servlet does not exist" error

in enviroment variables i set
・ PATH-----------,;%JAVA_HOME%\bin
・ JAVA_HOME--------------C:\Program Files\Java\jdk1.6.0_16
・ CATALINA_HOME-----------------C:\Program Files\Apache Software Foundation\Tomcat 5.5
・ CLASSPATH---------------,;%CATALINA_HOME%\common\lib\servlet-api.jar;%CATALINA_HOME%\common\lib\jsp-api.jar;




import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.io.*;
import javax.servlet.http.*;
import javax.servlet.*;


public class logj extends HttpServlet
{

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException
{


//initial settings to connect to database
Connection con=null;
ResultSet rs=null;
String uid=request.getParameter("t1");
String pswd=request.getParameter("t2");
String name="";
int b=0;


try
{
//display page should be of type html or text
response.setContentType("text/html");

//to use out for priting statements
PrintWriter out = response.getWriter();

//to set java properties
java.util.Properties prop=new java.util.Properties();
prop.load(new FileInputStream("F:/syskon"));
String DRIVER_NAME=prop.getProperty("jdbc.driver");
String URL=prop.getProperty("jdbc.url");
String USER=prop.getProperty("jdbc.user");
String PASS=prop.getProperty("jdbc.pass");



//to load a driver
Class.forName(DRIVER_NAME);

//to connect to database using con object
con=DriverManager.getConnection(URL,USER,PASS);
ServletContext sc = getServletContext();

PreparedStatement st=con.prepareStatement("select USER_ID,PASSWD,USER_NAME,MY_BALANCE from USER_MST");
rs=st.executeQuery();

while(rs.next())
{


if(uid.equals(rs.getString(1)) && pswd.equals(rs.getString(2)))
{
request.setAttribute("name",rs.getString("USER_NAME"));
request.setAttribute("b",rs.getInt("MY_BALANCE"));
sc.getRequestDispatcher("/2.jsp").forward(request,response);
}

else
sc.getRequestDispatcher("/login.jsp").forward(request,response);
}


rs.close ();
st.close ();
}
catch(Exception e1)
{
e1.printStackTrace();
}

}
}






please tell how to debug this
 
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You must first download j2ee sdk from sun, then place j2ee.jar in the classpath.
javax.servlet isn't in the standard j2se libraries.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

santhosh simha wrote:i am getting when i compile this servlet program i got "package javax.servlet does not exist" error

in enviroment variables i set
・ PATH-----------,;%JAVA_HOME%\bin
・ JAVA_HOME--------------C:\Program Files\Java\jdk1.6.0_16
・ CATALINA_HOME-----------------C:\Program Files\Apache Software Foundation\Tomcat 5.5
・ CLASSPATH---------------,;%CATALINA_HOME%\common\lib\servlet-api.jar;%CATALINA_HOME%\common\lib\jsp-api.jar;


First, check if servlet-api.jar and jsp-api.jar really exist in the indicated places.

It might be that the spaces in the directory names cause problems. Try putting directories with spaces in double quotes, like this:

set CLASSPATH="C:\Program Files\Apache Software Foundation\Tomcat 5.5\common\lib\servlet-api.jar";"C:\Program Files\Apache Software Foundation\Tomcat 5.5\common\lib\jsp-api.jar";.
 
Bartender
Posts: 4109
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

santhosh simha wrote:i am getting when i compile this servlet program i got "package javax.servlet does not exist" error

in enviroment variables i set
・ PATH-----------,;%JAVA_HOME%\bin
・ JAVA_HOME--------------C:\Program Files\Java\jdk1.6.0_16
・ CATALINA_HOME-----------------C:\Program Files\Apache Software Foundation\Tomcat 5.5
・ CLASSPATH---------------,;%CATALINA_HOME%\common\lib\servlet-api.jar;%CATALINA_HOME%\common\lib\jsp-api.jar;
.....


Can you try "echo %CLASSPATH%" in command prompt and post the output here? Also how are you compiling the code, which command you typed ?


 
Marshal
Posts: 77139
370
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please have a look at these FAQ. There might be something helpful there.
 
Campbell Ritchie
Marshal
Posts: 77139
370
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And welcome to JavaRanch
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic