Compiling java servlet programs

i have Tomcat 5.0 and SDK 1.5 . I am able to compile java programs. But in servlet programs the compiler is unable to recognize the javax.servlet package(the code below). I have pushed all the JAR files of TOMCAT to the CLASSPATH . But nothing has changed.
javax.servlet.*;
javax.servlet.Http.*;

hi,..
javax.servlet.Http.*; should be javax.servlet.http.*; !
even though you have put the jar files in the classpath .. does it point to servlet-api.jar ? if it does.. it should work. Also try out specifing the classpath using the -cp while compiling the servlet program .
--Olakara                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Similar Messages

  • Example of 'Java Servlet Programming, 2nd Edition' (O'reilly)

    Hi,
    I'm reading 'Java Servlet Programming, 2nd Edition' (O'reilly).
    I got a error "'.' expected" and "cannot resolve symbol"
    when trying JSP sample, hello3.jsp and HelloBean.java:
    I put hello3jsp to webapps/sample, and HelloBean.class
    to webapps/sample/WEB-INF/classes .
    Is this collect? If true, why I got the error?
    Could you give me any advices?
    hello3.jsp:
    (http://www.servlets.com/jservlet2/examples/ch18/hello3.jsp.txt)
    <%-- hello3.jsp --%>
    <%@ page import="HelloBean" %>
    <jsp:useBean id="hello" class="HelloBean">
      <jsp:setProperty name="hello" property="*" />
    </jsp:useBean>
    <HTML>
    <HEAD><TITLE>Hello</TITLE></HEAD>
    <BODY>
    <H1>
    Hello, <jsp:getProperty name="hello" property="name" />
    </H1>
    </BODY>
    </HTML>HelloBean.java:
    (http://www.servlets.com/jservlet2/examples/ch18/HelloBean.java)
    public class HelloBean {
      private String name = "World";
      public void setName(String name) {
        this.name = name;
      public String getName() {
        return name;
    }Error Message:
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occurred at line: 4 in the jsp file: /hello3.jsp
    Generated servlet error:
        [javac] Compiling 1 source file
    /usr/local/java/jakarta-tomcat-4.1.18/work/Standalone/localhost/sample/hello3_jsp.java:7: '.' expected
    import HelloBean;
                    ^
    /usr/local/java/jakarta-tomcat-4.1.18/work/Standalone/localhost/sample/hello3_jsp.java:44: cannot resolve symbol
    symbol  : class HelloBean
    location: class org.apache.jsp.hello3_jsp
          HelloBean hello = null;
          ^regards
    maco

    I got succeeded!
    I changed the three point:
    * add 'package hoo;' in HelloBean.java
    * add '<%@ page import="my.HelloBean" %>' in hello3.jsp
    * change '<jsp:useBean id="hello" class="HelloBean">
    to '<jsp:useBean id="hello" class="my.HelloBean">
    Before posting, I searched google three times but couldn't get answer.
    I could not get well if you didn't give me help...
    Thank you very much.

  • Inputting an excel file to the java servlet program

    Hi,
    How can I input an excel file into the java servlet program? I am using POI HSSF programming to read the content of that excel file.I have created a form that will accept the path from the user and in the servlet program, I have called a post method to retrieve the path of the file. I am getting the path of the file as a string.Then I have to access the file to read the data. But it is not working. What should I do?.Please help me.
    I have created an html file to create a form that will ask the path of the file to be loaded into the servlet program.Please give me a solution,thanks in advance. The servlet program that receives the file is shown below. It just only take the name of the file and prints if that is ok.
    <html>
    <body bgcolor="green">
    <center>
    <form method="post"  action="http://localhost:8080/examples/servlet/Ron1">
    <table>
    <tr>
    <td><B>ENTER THE PATH OF THE FILE</td>
    <td><input type=file name="path"></td>
    </tr>
    </table>
    <input type=submit value= "submit" >
    </form>
    </body>
    </html>
    import java.io.*;
    import javax.servlet.*;
    import java.lang.*;
    import javax.servlet.http.*;
    import java.sql.*;
    import java.text.*;
    import java.util.*;
    import com.oreilly.servlet.MultipartRequest;
    import org.apache.poi.hssf.usermodel.*;
    public class Ron1 extends HttpServlet
       public void doPost(HttpServletRequest request, HttpServletResponse response)   throws IOException, ServletException
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            String u = request.getParameter("FileToUpload");
            out.println("The Path is "+u);
            System.out.println("The path is "+u);
            MultipartRequest multi = new MultipartRequest(request,u,10 * 1024 * 1024);
            System.out.println("path is "+u);
            Enumeration files = multi.getFileNames();
            File fUploadedFile = null;
            String sFileName = "";
            out.println("path is "+u);
            while(files.hasMoreElements())
                            String name = (String)files.nextElement();
                            out.println("file is "+name);
                            sFileName = multi.getFilesystemName(name);
                            String type = multi.getContentType(name);
                            fUploadedFile = multi.getFile(name);
                    FileInputStream fis= new FileInputStream(fUploadedFile);
                   HSSFWorkbook wb=new HSSFWorkbook(fis);
                    System.out.println("The path is "+u);
                    out.println("File has identified successfully\n");
                    out.close();
       }

    Hi,
    Can you try to use classes from java.net package (URL, URLConnection) to pass the contents of excel file to servlet?
    HTH
    Vishal

  • Compiling Java Servlet with Depricated Methods

    I have a problem of compiling Java servlets that contain depricated methods. If you compile against modern version of servlet.jar I see depricated methods error messages and if I use a very old servlet.jar it cannot find newer methods. What is is the best solution in this case?
    Thank you,
    Boris.

    The best thing to do would be compile your code with the -depreciated option to find which methods have been depreciated and the refactor your code to remove them.
    The next best thing is to ignore the messages (they are warnings not errors) and your code should still work

  • Problem in compiling aa servlet program

    I have installed jsdk1.4.2_13
    And also installed tomcat 5.0.28
    I have set
    CATALINA_HOME==C:\Program Files\Tomcat\jakarta-tomcat-5.0.28
    JAVA_HOME ==C:\j2sdk1.4.2_13
    CLASS_PATH==
    C:\Program Files\Tomcat\jakarta-tomcat-5.0.28\common\lib\servlet-api.jar;
    C:\Program Files\Tomcat\jakarta-tomcat-5.0.28\common\lib\jsp-api.jar
    PATH ==C:\j2sdk1.4.2_13\bin;C:\Program Files\Tomcat\jakarta-tomcat-5.0.28\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem
    -->My java programs are compiling
    -->I can run tomcat server , And also can see starting page of "http://localhost:8080/"
    But I am not able to compile servlet program
    MY sevlet program is
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class HelloServlet extends HttpServlet {
    public void doGet(HttpServletRequest request,
    HttpServletResponse response)
    throws ServletException, IOException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    String docType =
    "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
    "Transitional//EN\">\n";
    out.println(docType +
    "<HTML>\n" +
    "<HEAD><TITLE>Hello</TITLE></HEAD>\n" +
    "<BODY BGCOLOR=\"#FDF5E6\">\n" +
    "<H1>Hello</H1>\n" +
    "</BODY></HTML>");
    ERRORS are:
    Pakage javax.servlet does not exist
    Pakage javax.servlet.http does not exist
    cannot resolve symbol HttpServletRequest
    and similar errors
    can anyone guide me?
    Message was edited by:
    Learn

    it's not CLASS_PATH, it's CLASSPATH.
    Directory paths with spaces in them are problematic. Surround them with double quotes.
    I think the best thing is not a CLASSPATH environment variable. Better to use the -classpath option on javac.exe when you compile.
    So your command to compile might look something like:
    javac -classpath .;"C:\Program Files\Tomcat\jakarta-tomcat-5.0.28\common\lib\servlet-api.jar" *.java%

  • How to & what to install to compile & run servlet programs

    Hi There,
    I want to know what software is the best suited in Java, for installation, by which i can compile and run my servlet programs.
    How to set the class path to run the servlet programs?
    to what file should my class path link?

    You can download and install Tomcat 3.2.x or 4.0 beta version.
    To run your servlet classes just copy them to your server's webapps directory to access them. You'll find all necessary information on the website.
    Here is the resource link:
    1. http://jakarta.apache.org/tomcat/
    Good Luck!
    Eshwar Rao
    Developer Technical Support
    Sun microsystems inc
    http://www.sun.com/developers/support

  • Application Server 4.0 caching the Java Servlet Program

    Hi all,
    I am working with Oracle8i databse and Oracle Application Server 4.0. Now I need to develop some Java Servlet's Program. I successful configure the server and my Servlet program can connect to the Oracle database.
    However, when I make some modification to the program and recompile it. The browser cannot refresh to the modified program. This mean that the content is't update. I think the reason may be the previous program is cached in server.
    Later, I discover using the 'owsctl' utility to reload the application server can solve this problem. However, it is quite inconvenience and not favour to reloasd the server very frequently. And I guess there may have some configuration parameters in the 'OAS Manager' can help me to solve my problem.
    So, anyone can tell me how to solve this problem? Thank you very much.
    Regards

    OAS 4.0.8.1 supports servlets. You need a patch if you implement extra path info feature of servlets. In addition, you have to bounce OAS everytime you upload new servlets. This behavior does not follow the Servlet spec and I don't know when Oracle will fix it. It is a big problem for sites trying to run 24x7.
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by dlnoida:
    Dear All,
    I have an application built in applets, i wants to host them on OAS 4.0.7.
    How can i do it if possible? Do i reqire any third party tool for it ?
    Is OAS 4.0.8 supports servlets?<HR></BLOCKQUOTE>
    null

  • Compile java servlet

    When compiling the servlet below I get the errors below:
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class HelloServlet extends HttpServlet
    public void doGet(HttpServletRequest req, HttpServletResponse res)throws Servlet
    Exception, IOException
    PrintWriter out = res.getWriter();
    out.println("<html>");
    out.println("<body>");
    out.println("<Hello Readers>");
    out.println("</html>");
    out.println("</body>");
    Why don't these packages exist?
    Thanks!
    /usr/java/j2sdk1.4.0/bin/javac HelloServlet.java
    HelloServlet.java:2: package javax.servlet does not exist
    import javax.servlet.*;
    ^
    HelloServlet.java:3: package javax.servlet.http does not exist
    import javax.servlet.http.*;
    ^
    HelloServlet.java:5: cannot resolve symbol
    symbol : class HttpServlet
    location: class HelloServlet
    public class HelloServlet extends HttpServlet
    ^
    HelloServlet.java:7: cannot resolve symbol
    symbol : class HttpServletRequest
    location: class HelloServlet
    public void doGet(HttpServletRequest req, HttpServletResponse res)throws Servlet
    Exception, IOException
    ^
    HelloServlet.java:7: cannot resolve symbol
    symbol : class HttpServletResponse
    location: class HelloServlet
    public void doGet(HttpServletRequest req, HttpServletResponse res)throws Servlet
    Exception, IOException
    HelloServlet.java:7: cannot resolve symbol
    symbol : class ServletException
    location: class HelloServlet
    public void doGet(HttpServletRequest req, HttpServletResponse res)throws Servlet
    Exception, IOException
    ^
    6 errors

    Those packages do exists.
    You just need to especify the JAR file where they are located in your classpath when compiling.
    Those packages are not part of the Java 2 Standard Edition (J2SE). Download the Enterprise Edition SDK (J2EE SDK) and use the servlet.jar when compiling.

  • How to compile java servlet

    this the error i encounter.. i have read some of the posted topics on it but i dont understand how i can create my own classpath..where should i do that..what should i write...how i have to save it...pls help me...
    C:\currentyaazmin1\java>javac login2.java
    login2.java:9: Package javax.servlet.http not found in import.
    import javax.servlet.http.*;
    ^
    login2.java:11: Package javax.servlet not found in import.
    import javax.servlet.*;
    ^
    login2.java:16: Superclass HttpServlet of class login2 not found.
    public class login2 extends HttpServlet
    ^
    3 errors
    i have already installed jdk1.3 an jsdk2.1...i also copied javax folder from jsdk2.1 and pasted in c:....still i encouter the same thing... pls help

    Download j2ee is recommended to solve any compling such as servlets and swing
    http://java.sun.com/j2ee/download.html
    Once done all you do is include j2ee.jar and you have xml, servlets, rmi the works!! :)
    However since you download the servelet component only, search in you hard drive for ".jar" file.
    You can open the .jar file with a WinZip and you can check if it as javax.servlet.http.* by looking at the far right for javax/servlet/http
    Once you know the jar file to include. Next is to put it in the classpath. The most simple way using NT example, how Windows 95/98 is similar. Go to:
    Control Panel -> Double Click on System -> Click on Environment tab
    Type below in Variable: CLASSPATH
    Type in Value: PATH TO SERVLET;.;
    Don't forget the ;.; (the dot for currnet path to run)
    If you need to add more to the classpath, seperate by classpath.
    Log off and log back in as your user. No need to reset the machine.
    The system will pick the new CLASSPATH.
    Test on dos as "echo %CLASSPATH%" to see what its set to.

  • Java servlet programming

    I am the beginner. So would you tell me what should I begin with? what should I need, and how should I do?
    What does this "http:/localhost:8080/servlet/Hello" means?
    Where can I identify the server and the port number?
    Thanks a lot!

    http:/localhost:8080/servlet/Hello
    it means
    http:// protocal
    localhost: ur current machine
    8080 the port no which we give at installation time
    servlet alies name for servlets folder which is recide webserver directory
    hello servlet class name
    u just try this
    1)install first j2sdk1.4.0 (or) later
    ex:
    c:\j2sdk1.4.0
    2)install second tomcat5.0
    ex:
    c:\tomcat5.0
    3) place the cursor on mycomputer and right click properties --> advance
         |
         environment (click this)
         |
         new
         |
         JAVA_HOME c:\j2sdk1.4.0 (ok,ok)
         new
         |
         CATALINA_HOME c:\tomcat5.0
         click path
         |
         (add at end) ;c:\j2sdk1.4.0\bin;c:\tomcat5.0\bin;
         new
         |
         CLASSPATH %classpath%;.;c:\tomcat5.0\common\lib\servlet-api.jar;
         now u restart the computer (or) tomcat server
         then in browser
         http://localhot:8080

  • I have jsdk2, but I can't compile servlet program

    I have jsdk2 version. which create in my c:\ dirve a folder jdk1.3. I do all the program from that. But I found that some of the class files of Servlet (servletRespose etc ) is missing. What I do to recover that. Even I can't compile any servlet program from that. Pls reply to my problems.
    Regards.
    Ranjan

    The Servlet API is part of J2EE (Java 2 Enterprise Edition). It is not included in the Standard Edition.
    So you need to download and install the J2EE reference implementation or another servlet engine such as Apache Tomcat ( http://jakarta.apache.org/tomcat ). Don't forget to put the Tomcat JAR files in your CLASSPATH when compiling your servlet program.
    Jesper

  • Java Servlet installation problem

    We have a Java Servlet program.
    To move into OAS.
    1.We need to configure the catridge(Done)
    2.We have to set the run time environment(I couldn't get this
    one)
    Oracle says two different methodology,
    1. From JDeveloper point of view
    2. From OAS point of view,
    I am not very clear in setting the environment variables and
    moving the files.
    Regards
    Nirmal
    null

    Hi,
    I think your problem has to do with your classpath. When compiling java classes, you must specify a classpath that the compiler will use to resolve your import statments. Since you are compiling a servlet, you must include the jar file that contains the javax.servlet package. Since you've installed the j2sdkee 1.3.1, you'll find the javax.serlvet package within the j2ee.jar file within the J2SDKEE 1.3.1 lib directory. So your javac command should look like this:
    javac -classpath <j2sdkee1.3.1 directory>/lib/j2ee.jar Test.java
    ( where j2sdkee1.3.1 directory is the path to where you installed the j2sdkee 1.3.1 ).
    I hope this helps?
    Cheers
    Jeff

  • How to Compile/Run servlet in Tomcat 4.1

    Hi All,
    iam trying to compile my servlet program in tomcat4.1.. but its showing an error
    in the import statement..
    UN SOLVABLE SYMBOL... but the import ststement is correct...
    can any one help ... is there i have to set any path for compiling/running the servlet...
    Thanks in Advice

    hi thanks for your reply
    i have loaded tomcat4.1 exe -- for windows i am starting the tomcat server by clicking from the start menu..
    i dint set any env variable .. tell me how to set...
    regards
    ijay

  • Java servlet class access

    Can a servlet running on server A access a class defined on server B?
    More information:
    I am new at Java servlet programming and want to make sure that my web application is secure. I have set up a Java class that returns some user information (name, email address etc) and I have set up some jsp and servlet pages that access the class via an 'import my.class...' for servlets and a '@page import ="my.class..." 'for jsp. The jsp and servlet pages do session checking and authentication but the class does none of that - it's methods just return the requested data. I do not want to put any authentication in the class but I want to be certain that there is no way some other web server out on the internet could access this class in my web application. I do not think it is possible but my fear is that some hacker out there could somehow remotely do an @page import "my.class..." on my webserver and then gain access to my class methods? These web apps are running inside a Glassfish 3.0 app server.
    Thanks!

    user479480 wrote:
    That is very helpful info. I have been writing a lot of functional type code (updating, selecting and returning database data etc) inside Java servlets but when I get a new requirement I end up rewriting the same code in new servlet pages. So I have been thinking of putting all of that functional code in classes that I can re-use but was unsure of the security access and did not want to clutter the classes up with a bunch of session/authentication checking.
    Do you recommend any books on J2EE Web programming? Thanks again for your assistance.Code re-use isn't a problem that way, because you can put your common code into a library jar and use it in as many JVMs as you like. What you can't do is to access any Java objects running in one JVM from another one, whether or not they are on the same machine.

  • Compiling a servlet

    Hi,
    I am using jakarta-tomcat-4.0, to which jar file I have to set the classpath inorder to compile a servlet program.
    Thanks

    <TOMCAT>\common\lib\servlet.jar

Maybe you are looking for

  • How can I create packages procedure & function in user-define Library

    hi. i am already created packages procedure & function in database and use so on. now i would like to create these in library file. please anyone give me example of any procedure or function to store in library. thanks Ali

  • Delete BLOB image without deleting associated row?

    We have some BLOB data stored out of line. The rows associated with it have been set to NULL, but the image files remain and are filling the tablespace. Is there any way of getting rid of the images without deleting their associated rows? We have als

  • WHY DOES THE PE EDITOR KEEP FAILING TO LOAD

    I have a brand new problem with Photoshop Elements 8, which I've been using in Windows for several years. Suddenly the PE editor refuses to load--either from "Fix" in the album space or from "Edit" in the Workspace. It starts to load (with the green

  • Strange reconciliation issue

    New blackberry curve verizon user here.  Successfully added my .edu IMAP account and can send and receive emails.  After reading messages on the curve, they show as read on outlook and on the university's webmail site.  If I delete a message on the c

  • Anyone know how to get a copy of a IBM 7845I2 Recovery Disk?

    Anyone know how to get a copy of a IBM 7845I2 Recovery Disk?, My multipoint switch is stuck in read only mode -  Please use Recovery Disk to check the file system using fsck.