File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes  package javax.servlet.http 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.http does not exist" Watch " package javax.servlet.http does not exist" New topic
Author

package javax.servlet.http does not exist

saravanan rajendran
Ranch Hand

Joined: Jun 13, 2008
Posts: 75
this is the code:

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.ServletException;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.asteriskjava.manager.AuthenticationFailedException;
import org.asteriskjava.manager.ManagerConnection;
import org.asteriskjava.manager.ManagerConnectionFactory;
import org.asteriskjava.manager.TimeoutException;
import org.asteriskjava.manager.action.OriginateAction;
import org.asteriskjava.manager.response.ManagerResponse;
import org.asteriskjava.manager.action.ManagerAction;

public class Outbound extends HttpServlet {

private ManagerConnection managerConnection;
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {

PrintWriter out = response.getWriter();


//pasted from http://asterisk-java.org/development/tutorial.html :-)

try {

ManagerConnectionFactory factory = new ManagerConnectionFactory(
"192.168.1.186", "admin", "1234"); //

this.managerConnection = factory.createManagerConnection();


OriginateAction originateAction;
ManagerResponse originateResponse;

originateAction = new OriginateAction();
//originateAction.setChannel("SIP/YOUR_TRUNK_NAME/"+name);
originateAction.setChannel("local"+'/'+"5101");
originateAction.setContext("default");
originateAction.setExten("284818");
originateAction.setPriority(new Integer(1));
originateAction.setTimeout(new Long(30000));


// connect to Asterisk and log in
managerConnection.login();

// send the originate action and wait for a maximum of 30 seconds for Asterisk
// to send a reply
originateResponse = managerConnection.sendAction(originateAction, 30000);




// and finally log off and disconnect
managerConnection.logoff();

out.println("OK");
} catch (Exception e) {
out.println("NOT OK");
e.printStackTrace();


}

}
}

I compile that code getting this error

: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
Outbound.java:12: cannot find symbol
symbol: class HttpServlet
public class Outbound extends HttpServlet {
^
Outbound.java:15: cannot find symbol
symbol : class HttpServletRequest
location: class Outbound
public void doGet(HttpServletRequest request,
^
Outbound.java:16: cannot find symbol
symbol : class HttpServletResponse
location: class Outbound
HttpServletResponse response)
^
Outbound.java:17: cannot find symbol
symbol : class ServletException
location: class Outbound
throws ServletException, IOException {

i given export classpath but problem not sloved please reply
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42602
    
  65
Welcome to JavaRanch.

Which command, exactly, are you using to compile? Generally I advise to use the javac "-classpath" switch for specifying libraries instead of using the CLASSPATH environment variable.


Ping & DNS - my free Android networking tools app
saravanan rajendran
Ranch Hand

Joined: Jun 13, 2008
Posts: 75
this is for compile:javac -cp asterisk-java-0.3.1.jar Outbound.java
this is fro export: export CLASSPATH=/var/lib/asterisk/agi-bin/servlet-api.jar
please help me
akhilesh pandey
Greenhorn

Joined: Jun 03, 2008
Posts: 17
Is j2ee.jar in your classpath?
saravanan rajendran
Ranch Hand

Joined: Jun 13, 2008
Posts: 75
yes i have servlet-api.jar that only i exported into classpath
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42602
    
  65
Try including it in the javac command like the other library.
saravanan rajendran
Ranch Hand

Joined: Jun 13, 2008
Posts: 75
yes javac command working. i first time running this asterisk manager api code please help me

i setted path but it giving this error: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
Outbound.java:12: cannot find symbol
symbol: class HttpServlet
public class Outbound extends HttpServlet {
^
Outbound.java:15: cannot find symbol
symbol : class HttpServletRequest
location: class Outbound
public void doGet(HttpServletRequest request,
^
Outbound.java:16: cannot find symbol
symbol : class HttpServletResponse
location: class Outbound
HttpServletResponse response)
^
Outbound.java:17: cannot find symbol
symbol : class ServletException
location: class Outbound
throws ServletException, IOException {
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3739
    
  16
Originally posted by saravanan rajendran:
this is for compile:javac -cp asterisk-java-0.3.1.jar Outbound.java
this is fro export: export CLASSPATH=/var/lib/asterisk/agi-bin/servlet-api.jar
please help me


If you use the -cp option then javac will ignore the CLASSPATH setting. You have to use one or the other.


Joanne
saravanan rajendran
Ranch Hand

Joined: Jun 13, 2008
Posts: 75
thanks i got it thank you very much for yr help
saravanan rajendran
Ranch Hand

Joined: Jun 13, 2008
Posts: 75
when i run getting this error please help me:


java -cp servlet-api.jar :.:asterisk-java-0.3.1.jar Outbound
Exception in thread "main" java.lang.NoClassDefFoundError: :/:asterisk-java-0/3/1/jar
Caused by: java.lang.ClassNotFoundException: :.:asterisk-java-0.3.1.jar
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
-bash-3.1# java -cp servlet-api.jar :.:asterisk-java-0.3.1.jar Outbound
Exception in thread "main" java.lang.NoClassDefFoundError: :/:asterisk-java-0/3/1/jar
Caused by: java.lang.ClassNotFoundException: :.:asterisk-java-0.3.1.jar
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
saravanan rajendran
Ranch Hand

Joined: Jun 13, 2008
Posts: 75
now my compiling is working when i try to run it getting error:Exception in thread "main" java.lang.NoSuchMethodError: main
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3739
    
  16
That's because you are writing a Servlet, not an application. Servlets have to be hosted by a server of some sort. For an HTTPServlet like you've written this would be a Web Server. Check out the Servlet tutorial or the tutorial you linked to in your original post for more details.
Naren Mane
Greenhorn

Joined: Mar 02, 2011
Posts: 16

]Hi,

Against CLASSPATH environment variable you should add path as "D:\SWs\apache-tomcat-7.0.2-windows-x86\apache-tomcat-7.0.2\lib\*;". This works for me....always. Just try this.Here you should replace "D:\SWs\apache-tomcat-7.0.2-windows-x86\apache-tomcat-7.0.2\lib" with path of tomact on your system.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: package javax.servlet.http does not exist