Cannot Import javax.servlet.* and javax.servlet.http.*

Hello,
I am a University Student and now doing a project using Servlet and JSP
I have installed WinXP and Tomcat 5.0 on my computer
When I compile the servlet , there are error messages "package javax.servlet does not exist" and "package javax.servlet.http does not exist" coming out.
I have set the classpath already
i.e. %CATALINA_HOME%\common\lib\servlet-api.jar;%CATALINA_HOME%\common\lib\jsp-api.jar
( Of course "%CATALINA_HOME%" = my folder that install the Tomcat )
Can Anybody Explain what is happening and suggest a solution to me?
Please give a hand.

When you ran that command, what happened? Let javac.exe tell you the right answer.
I'd advise two things:
(1) Installing any s'ware in a directory whose name contains spaces (e.g., "Apache Software Foundation" or "Tomcat 5.0") is a very bad idea, IMO. I'd reinstall to a new directory.
(2) Your HelloServlet.java servlet probably doesn't have a package statement in it. Tomcat 5.0 won't play nicely with servlets or beans that aren't in packages. I'd add one and use the -d . option on javac.exe to make sure it created the package directory structure for me.

Similar Messages

  • Problems Compiling javax.servlet and javax.servlet.http

    When I try to compile a program that imports both javax.servlet and javax.servlet.http, the compiler keeps telling me that "package javax.servlet does not exist"... I have place the javax.servlet packages in the src.zip and in the src folder but i dont understand why the compiler isnt picking them up. Maybe I did something wrong ... could someone help please

    Try to compile vith the option "-classpath /your/path/to/servlet.jar"

  • Cannot import javax.servlet onto classpath

    Hi guys, newbie question.
    Im using jedit on linux; compiling with j2sdk1.4.2_04 but it will not pick up the javax.serlet
    classes!! Is there an add on I need to download to develop j2ee stuff, as I thought j2sdk1.4.2_04 was all that was required.
    Thanks in advance

    Wrong. You need a JAR that has the javax.servlet and javax.servlet.http packages, and they don't come with the J2SE.
    If you want to run servlets/JSPs, you must have a servlet/JSP engine. If you already have one, root around for the servlet JAR. If don't, download Tomcat. It's Sun's reference implementation for the servlet/JSP specifications. The servlet JAR will be in the TOMCAT_HOME/common/lib directory.

  • J2se vs j2ee javax.servlet.* & javax.servlet.HTTPServlet

    Hi,
    I guess I have a basic question....It is in j2se 1.4.2 API's one does not have the package javax.servlet.* or javax.servlet.HttpServer package/classes.How does one get to compile the java source file if it imports javax.servlet.* and javax.servlet.HttpServlet.,both of these are present in the j2ee API's.Help would be greatly appreciated.
    Thanks
    AS

    Yup, pretty basic.
    You're right - the javax.servlet and
    javax.servlet.http packages are not part of the J2SE.
    However, they are part of every servlet/JSP engine
    you can find, including Tomcat and Sun ONE J2EE app.
    Look for a j2ee.jar or servlet.jar (or servlet-api.jar
    if you're using Tomcat 5.0.x) and you'll find those
    classes. Once you locate the proper JAR, all you have
    to do is make sure it's in your CLASSPATH when you
    compile and run:
    javac -classpath .;/full/path/to/servlet.jar *.java
    MODThanks for the reply.So if we compile it we will get compile errors right?,without the appropriate classpath settings.Got you.
    AS

  • Help With Integrating Servlet and JSP Page?

    Hello There
    --i made jsp page that contain name and description fields and add button
    --and i made servlet that contain the code to insert name and description in the database
    --and i want to make that when the user hit the add button
    -->the entered name and description is sent to the servlet
    and the servlet sent them to database?
    here's what i 've done:
    the jsp code:
    <html:html locale="true">
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>
            Categories Page
           </title>
            <html:base/>
        </head>
        <body style="background-color: white">
        <form action="jpage.jsp" method="get">
            <h1>
                <center>
    categories Operations
                </center>
            </h1>
            <h3>
                 <label>Name</label>
            <input type="text" name="name" value="" size="10" />
                 <label>Description</label>
             <input type="text" name="description" value="" size="10" />
             <input type="submit" value="Add" name="button" />
           </h3>
       </form>
        </body>
    </html:html>the servlet code:
    import java.io.*;
    import java.util.Enumeration;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.sql.*;
    import java.net.*;
    class NewServlet1 extends HttpServlet{
         Connection conn;
         private ServletConfig config;
    public void init(ServletConfig config)
      throws ServletException{
         this.config=config;
    public void service (HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException {
       HttpSession session = req.getSession(true);
       res.setContentType("text/html");
    try{
         Class.forName("com.mysql.jdbc.Driver");
       conn = DriverManager.getConnection("jdbc:mysql://localhost/struts", "root", "");
         PreparedStatement ps;
       ps = conn.prepareStatement ("INSERT INTO categories (Name, Description) VALUES(?,?)");
          ps.setString (1, "aa");
          ps.setString (3, "bb");
          ps.executeUpdate();
          ps.close();
          conn.close();
      }catch(Exception e){ e.getMessage();}
      public void destroy(){}
    }

    The JSP Code:
    <html:html locale="true">
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>
            Categories Page
           </title>
            <html:base/>
        </head>
        <body style="background-color: white">
        <form action="actionServlet.do?action=Additem" method="*post*">
            <h1>
                <center>
    categories Operations
                </center>
            </h1>
            <h3>
                 <label>Name</label>
            <input type="text" name="name" value="" size="10" />
                 <label>Description</label>
             <input type="text" name="description" value="" size="10" />
             <input type="button" value="Submit">
           </h3>
       </form>
        </body>
    </html:html>The Servlet Code:
    import java.io.*;
    import java.util.Enumeration;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.sql.*;
    import java.net.*;
    public class NewServlet1 extends HttpServlet implements SingleThreadModel {
        public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException {
            doPost(request,response);
        public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException {
              String action = request.getParameter("action"); // action = "Additem"
              if (action.equals("Additem")) {
                   String name = request.getParameter("name");
                   String description = request.getParameter("description");
                         RequestDispatcher reqDisp = null;
                   try{
                  Connection conn;
                  PreparedStatement ps;
         Class.forName("com.mysql.jdbc.Driver");
       conn = DriverManager.getConnection("jdbc:mysql://localhost/struts", "root", "");
       ps = conn.prepareStatement ("INSERT INTO categories (Name, Description) VALUES(?,?)");
          ps.setString (1, name);
          ps.setString (3, description);
          ps.executeUpdate();
          ps.close();
          conn.close();
          reqDisp= request.getRequestDispatcher("./index.jsp");
          reqDisp.forward(request, response);
                   catch (Exception ex){
                        System.out.println("Error: "+ ex);
    }The web.xml code:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
        <servlet>
            <servlet-name>action</servlet-name>
            <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
            <init-param>
                <param-name>config</param-name>
                <param-value>/WEB-INF/struts-config.xml</param-value>
            </init-param>
            <init-param>
                <param-name>debug</param-name>
                <param-value>2</param-value>
            </init-param>
            <init-param>
                <param-name>detail</param-name>
                <param-value>2</param-value>
            </init-param>
            <load-on-startup>2</load-on-startup>
            </servlet>
        <servlet>
            <servlet-name>NewServlet1</servlet-name>
            <servlet-class>NewServlet1</servlet-class>
        </servlet>
        <servlet-mapping>
            <servlet-name>action</servlet-name>
            <url-pattern>*.do</url-pattern>
        </servlet-mapping>
        <servlet-mapping>
            <servlet-name>NewServlet1</servlet-name>
            <url-pattern>/NewServlet1</url-pattern>
        </servlet-mapping>
        <session-config>
            <session-timeout>
                30
            </session-timeout>
        </session-config>
        <welcome-file-list>
            <welcome-file>index.jsp</welcome-file>
            </welcome-file-list>
            <servlet>
         <servlet-name>actionServlet</servlet-name>
         <servlet-class>com.test.servlet.NewServlet1</servlet-class>
    </servlet>
    <servlet-mapping>
         <servlet-name>actionServlet</servlet-name>
         <url-pattern>*.do</url-pattern>
    </servlet-mapping>
        </web-app>

  • How to compile and execute servlet file in j2ee

    In j2ee server when iam compiling servet i am getting error messages like package javax.servlet,and javax.servlet.http does not exist like that.
    i hsve set path like this.and i gave path for j2sdk .
    set CPATH=.;%J2EE_HOME%\lib\j2ee.jar
    javac -classpath %CPATH% AdderServlet.java
    can anybody tell me where to place
    servlet and how to compile it.
    Thank u,
    Renuga

    Make sure that '%J2EE_HOME%\lib\j2ee.jar' is existing. Where is your J2EE_HOME pointing to?
    The best thing I can suggest is, create your own bat file to compile the servlets. Like this,
    Save the lines below as "MyCompiler.bat" file.
    @echo off
    set JDK_HOME=<path to you jdk home upto bin directory>
    set J2EE_HOME=<path to you je22 home>
    set CLASSPATH=.;%J2EE_HOME%\lib\j2ee.jar
    %JDK_HOME%\javac %1
    Use the command,
    MyCompiler AdderServlet.java
    You can improve this MyCompiler.bat further, can add additional jar files to the classpath whenever you want. You can put this bat file in System's path, so that you can invoke it just by the name (MyCompiler) without giving the full path to it (like C:\mydir\MyCompiler).
    Hope this helps.
    Sudha

  • Javax.crypto.* and javax.crypto.spec.* problem with MHP receiver

    Hello to everyone, I started to program in MHP 1.0.2 on a MHP receiver and now i'm practicing in encrypting and decrypting. I load from the smart card in the MHP receiver an X509Certificate object (I have it both in byte[] form, called certArray, and X509Certificate object, called "certificate"). What i'd like to do is to :
    1)calculate digest of the certificate (line 1 and 2 of the following code)
    2) encrypt the digest using the same algorithm of the certificate (see line 3 and 4)
    The problem is generated at line 3 : the receiver, probably, doesn't find the class of the algorithm of encrypting. It is important to notice that the instruments to encrypt/decrypt are included in javax.crypto and javax.crypto.spec packages.
    MessageDigest md = MessageDigest.getInstance("SHA");
    byte[] digest = md.digest(certArray);
    Cipher encrypt = Cipher.getInstance(certificate.getSigAlgName());
    encrypt.init(Cipher.ENCRYPT_MODE, certificate.getPublicKey());
    The error message, in the log file, is the following :
    [0#1:2] java.security.NoSuchAlgorithmException: SHA1withRSA not found
         [0#1:2]      at javax.crypto.Cipher.getInstance(Ljava/lang/String;)Ljavax/crypto/Cipher;(Unknown Source)
         [0#1:2]      at it.csp.SecurelabXlet.encrypt()V(Unknown Source)
         [0#1:2]      at it.csp.SecurelabXlet.cardInserted(Lopencard/core/event/CardTerminalEvent;)V(Unknown Source)
         [0#1:2]      at opencard.core.event.EventGenerator.createEventsForPresentCards(Lopencard/core/event/CTListener;)V(Unknown Source)
         [0#1:2]      at it.csp.SecurelabXlet.register()V(Unknown Source)
         [0#1:2]      at it.csp.SecurelabXlet.startXlet()V(Unknown Source)
         [0#1:2]      at java.lang.reflect.Method.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;(Unknown Source)
         [0#1:2]      at tv.osmosys.application.AppManager$XletApp.xletStart()Z(Unknown Source)
         [0#1:2]      at tv.osmosys.application.AppManager$XletApp.loop0(Ltv/osmosys/application/AppManager$XletAction;)V(Unknown Source)
         [0#1:2]      at tv.osmosys.application.AppManager$XletApp.run()V(Unknown Source)
         [0#1:2]      at java.lang.Thread.run()V(Unknown Source)
         [0#1:2]      at java.lang.Thread.startup(Z)V(Unknown Source)
    My question(s) is : how can I include javax.crypto and javax.crypto.spec in the Xlet application to upload it onto the MHP receiver?? Is it possibile to do so?
    Eventually, do other libraries exist to use encrypting algorithms, included in MHP? The version I use of MHP is 1.0.2. Thank you! Bye!

    Hello to everyone, I started to program in MHP 1.0.2 on a MHP receiver and now i'm practicing in encrypting and decrypting. I load from the smart card in the MHP receiver an X509Certificate object (I have it both in byte[] form, called certArray, and X509Certificate object, called "certificate"). What i'd like to do is to :
    1)calculate digest of the certificate (line 1 and 2 of the following code)
    2) encrypt the digest using the same algorithm of the certificate (see line 3 and 4)
    The problem is generated at line 3 : the receiver, probably, doesn't find the class of the algorithm of encrypting. It is important to notice that the instruments to encrypt/decrypt are included in javax.crypto and javax.crypto.spec packages.
    MessageDigest md = MessageDigest.getInstance("SHA");
    byte[] digest = md.digest(certArray);
    Cipher encrypt = Cipher.getInstance(certificate.getSigAlgName());
    encrypt.init(Cipher.ENCRYPT_MODE, certificate.getPublicKey());
    The error message, in the log file, is the following :
    [0#1:2] java.security.NoSuchAlgorithmException: SHA1withRSA not found
         [0#1:2]      at javax.crypto.Cipher.getInstance(Ljava/lang/String;)Ljavax/crypto/Cipher;(Unknown Source)
         [0#1:2]      at it.csp.SecurelabXlet.encrypt()V(Unknown Source)
         [0#1:2]      at it.csp.SecurelabXlet.cardInserted(Lopencard/core/event/CardTerminalEvent;)V(Unknown Source)
         [0#1:2]      at opencard.core.event.EventGenerator.createEventsForPresentCards(Lopencard/core/event/CTListener;)V(Unknown Source)
         [0#1:2]      at it.csp.SecurelabXlet.register()V(Unknown Source)
         [0#1:2]      at it.csp.SecurelabXlet.startXlet()V(Unknown Source)
         [0#1:2]      at java.lang.reflect.Method.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;(Unknown Source)
         [0#1:2]      at tv.osmosys.application.AppManager$XletApp.xletStart()Z(Unknown Source)
         [0#1:2]      at tv.osmosys.application.AppManager$XletApp.loop0(Ltv/osmosys/application/AppManager$XletAction;)V(Unknown Source)
         [0#1:2]      at tv.osmosys.application.AppManager$XletApp.run()V(Unknown Source)
         [0#1:2]      at java.lang.Thread.run()V(Unknown Source)
         [0#1:2]      at java.lang.Thread.startup(Z)V(Unknown Source)
    My question(s) is : how can I include javax.crypto and javax.crypto.spec in the Xlet application to upload it onto the MHP receiver?? Is it possibile to do so?
    Eventually, do other libraries exist to use encrypting algorithms, included in MHP? The version I use of MHP is 1.0.2. Thank you! Bye!

  • HT5129 Every time iPhoto scans my Mobilme albums for import, it freezes and does not complete. Any ideas?

    Every time my iPhoto prompts to import my Mobilme albums, it freezes iPhoto and I have to force quit to continue.
    Any ideas? It cannot import my albums.
    Thanks

    Go to http://web.me.com and use the Sign In link to go to your galleries:
    There you can use the Download button to download all of you gallery photos grouped by gallery.
    When you're done  go to iPhoto's Accounts preference pane and delete the MobileMe account. Next to go the Sustem/MobileMe preference pane and log out of MMe.  That will stop those messages.
    OT

  • TS3682 I cannot download my music and photos from my computer to my new iphone 5

    I cannot import my music and photos from my computer to my new iphone 5.

    Perform a backup to iTunes from the old device and then a restore to the new device, use ITunes to do this.  BTW, always sync photos to a computer to store them safely (use iPhoto on a mac or to a designated folder on a PC).  Never trust an iOS device to keep photos without having them synced to a computer.

  • HT2635 What does this mean? "I Photo cannot import your photos because there is not enough free space on the volume containing your I photo library"

    I cannot import my pictures and movies from a DVD - What does this mean when I get a computer message on my Mac -
    "I photo cannot import your photos because there is not enough free space on the volume containing your I photo library"

    It means pretty much what it says - your HD is full.
    This can arise because your HD is full - how big is your HD? How much free space on it?
    Or it can be a mis-report due to to other issues.
    Regards
    TD

  • Javax.jms versus  javax.mail

    Are javax.jms and javax.mail related in any way?
    Both share similar concepts, but are they in any way interdependent on each other?

    The only they have in common they are both included into J2EE.
    JavaMail provides the email processing on a top of SMTP/POP3
    e-mail protocol. Generally If you want to send/receive e-mail you
    can just use TCP and SMTP/POP3. But it is much better to use
    JavaMail.
    JMS is the messaging system provided the communication between
    Enterprize Java components and is not related to SMTP.
    vpanasenko_even

  • Cannot import javax.servlet

    Hello,
    I'm trying to write a javabean to use with in jsp code.
    In the bean I need to use <code>HttpServletResponse and for this I need to add :
    </code>import javax.servlet.*;
    import javax.servlet.http.*;
    this throws me the exception : package javax.servlet does not exist.
    CLASSPATH = .;D:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\servlet-api.jar;D:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\jsp-api.jar;D:\Program Files\Apache Software Foundation\Tomcat 6.0\lib\el-api.jar;
    I have no idea where I need to include this class.
    Thanks in advance for your help.

    No idea about Netbeans, but in Eclipse you can just accosiate an application server with the web project, then it will automatically take its libraries (the javax.servlet and so on) in the buildpath.

  • Javax.servlet.*, javax.servlet.http are mot getting resolved in eclipse 3.2

    Can any one tell why after importing javax.servlet.* and javax.servlet.http is not getting resolved in eclipse 3.2 IDE.

    right click on the project in the navigator window and select properties.
    you will get property window and then select library tab and click the add library button to add the jar file in which javax.serv... packages are defined.

  • Creating a Servlet (javax.servlet.* & javax.servlet.http.*)

    Hello,
    I am writing my first servlet and I need to include the following 2 packages (javax.servlet.* & javax.servlet.http.*). I have J2SE & J2EE installed on my machine, but I am still unable to compile because I am missing these important packages. Perhaps I have a partial install or I need to get these from another site? I did look in my lib & bin directories and searched my all my hard drives. I would appreciate if some one can help me out.
    Joyce

    You need to make sure that servlet.jar is in your classpath or that you add it to your 'java' argument list when compiling your files. So if you're using Windows you'd do something like:
    c:\java -classpath c:\j2ee\servlet.jar MyServlet.java

  • Package javax.servlet.* and javax.xml.rpc.*

    Which jar file(s) in Oracle WebLogic Server 10.3 contain these two packages: package javax.servlet.* and javax.xml.rpc.*? Where are they located? Thanks

    I don't have access to my WLS installation right now, but normally I use a class finder utility like this one to answer questions like this:
    http://www.inetfeedback.com/jarscan/

Maybe you are looking for

  • Radio button in alv report

    Hi experts, I am using radio buttons in alv report by using screen painter but error occurs in alv that screen doesn't exist in module. plz help me.

  • An error occurred creating the form (task 2346, form 0). (ALC-WKS-007-040) error

    Hi all, I am a newbie to adobe livecycle process. I am trying to prepopulate the data like the users info when the form is originated in the workspace. I did use the samples example for form render service but added to variables called first and last

  • Any ideas for how to mount my iPhone to my guitar (as in the opening sequence in the ad)?

    Any ideas for how to mount my iPhone to my guitar (as in the opening sequence in the ad)? Thanks for your thoughts- I'm looking for something non-damaging to the guitar but secure so I don't drop the phone. Frank

  • Cannot publish

    I am trying to publish my project and I keep getting an error message that reads: swf.compilation failed. action script is used as user variable name. Can anyone help me fix this and be able to publish my project - it is very urgent. Any help would b

  • Applications constantly quitting unexpectedly and not responding

    Lately, my computer has been having quite a bunch of issues. One of the major ones is applications constantly crashing and quitting unexpectedly. For example, when I want to go edit a video with iMovie, I have to literally reopen it 5 times just so t