This week's book / license giveaways are in the JDBC and Relational Databases and Java in General forums.
We're giving away four copies each of PostGIS in Action and Java Advanced Topics Training and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes 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 "package javax.servlet does not exist" Watch "package javax.servlet does not exist" New topic
Author

package javax.servlet does not exist

santhosh simha
Greenhorn

Joined: Oct 01, 2009
Posts: 1
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

Joined: Jun 21, 2008
Posts: 423
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

Joined: Aug 16, 2005
Posts: 14706
    
  25

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";.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3882

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 ?



SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 41879
    
  31
Please have a look at these FAQ. There might be something helpful there.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 41879
    
  31
And welcome to JavaRanch
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: package javax.servlet does not exist