• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

package javax.servlet does not exist

 
santhosh simha
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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
 
Ireneusz Kordal
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • 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.
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15481
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • 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";.
 
Vijitha Kumara
Bartender
Pie
Posts: 3918
10
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • 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 ?


 
Campbell Ritchie
Sheriff
Pie
Posts: 50175
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please have a look at these FAQ. There might be something helpful there.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50175
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to JavaRanch
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic