Cannot run a servlet using Tomcat. Urgent

I have a webapplication which uses some jsp's and servlets. The jsp pages work fine when I use
http://hostname:8080/MyWebapp/Filename.jsp
However, when I developed a java servlet and put the class file in WEB-INF/classes directory of my web application and tried to access it.
I got a resource not found error.
The strange thing is that when I put the file in the web-inf/classes folder of examples webapplication (which comes with Tomcat) I am able to run the servlet using
http://hostname:8080/examples/servlet/Class file
I am not sure what is wrong.
Can someone help me.
Thanks in advance
Vamsi.

It's predictable. The Servlet and JSP specifications mandate that you cannot directly access resources under WEB-INF directory. You have to set up servlet mapping configuration in your web.xml to specify how to access the resources, both Servlet and JSP, there.
When you copied your files in a demo webapp of Tomcat, the web.xml of the demo app already set up the mapping like following for you. So you could use http://hostname:8080/examples/servlet/Class to visit the servlet.
<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>
The default setting since Tomcat 4.1 turned off servlet invoker in web.xml under conf directory. You can uncomment the above lines in this file to turn it on. Then you are able to visit your servlet without <servlet-mapping> configured using the following syntax,
http://hostname:8080/<your_app_name>/servlet/<your_servlet_name>

Similar Messages

  • How to run a servlet in tomcat 5.5

    Hi,iam new to servlets,please help me regarding running a servlet in tomcat 5.5,
    I just want an example servlet to run first,
    the below is the code for the same :-
    //ExampleServlet.java
    package sig;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class ExampleServlet extends HttpServlet {
         public void init(ServletConfig config) throws ServletException{
              super.init(config);
         public void service(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException{
              PrintWriter out = res.getWriter();
              out.println("<HTML>");
              out.println("<BODY>");
              out.println("<p>Hello World</p>");
              out.println("</BODY>");
              out.println("</HTML>");
    I have created a new folder named "SignatureServlet" under the "webapps" folder of tomcat and have created a "WEB-1NF" folder under it,
    again i have kept my "ExampleServlet.class" inside the "WEB-1NF->classes" folder and the entries for my servlet in the "web.xml" file are:-
    <servlet>
    <servlet-name>ExampleServlet</servlet-name>
    <servlet-class>ExampleServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>ExampleServlet</servlet-name>
    <url-pattern>/ExampleServlet</url-pattern>
    </servlet-mapping>
    still when iam trying to access the servlet using "http://localhost:8080/ExampleServlet/"
    iam getting a HTTP:404 error
    The requested resource () is not available.,
    please help

    You better ask this on a Tomcat forum...
    Timo

  • Cannot run a servlet in the IDE.

    Under which webapps we need to put the file folders of my project.
    I cannot run the servlet It gets deployed and
    if I try to invoke the servlet using the url name it gives
    this error
    [30/Nov/2004:17:08:41] WARNING ( 5996): for host 127.0.0.1 trying to GET /appshub, send-file reports: HTTP4142: can't find C:/Sun9/jstudio/AppServer7/domains/domain1/server1/applications/j2ee-modules/project_3/appshub (File not found)
    Every time I do a deploy it creates a new instance ../project_1/appshub
    second time ../project_1/appshub
    please help with this problem..
    Vijay

    Hi Vijay
    You need to create the servlets under WEB-INF->classes tree.
    Here is the structure of a simple web module shown in FIle System tab of IDE
    -/export/home/JSEApps/MyApp
    -- WEB-INF -->classes-->mypackage-->MyServlet
    -- MyJsp
    Once you created and compiled the servlets like this, right click on WEB-INF folder in the IDE and change the context root property to /myapp . Again right click on WEB-INF and deploy.
    Now you can access the servlet with http://server:port/myapp/servlet/ MyServlet
    Check the documentation @ http://docs.sun.com/source/817-2334/index.html on how to build web componets.
    check this for complete documentation. http://docs.sun.com/app/docs/coll/790.6
    Check few samples @ http://developer.sun.com/prodtech/javatools/jsenterprise/learning/tutorials/index.html
    Let me know if you need more.
    Thanks
    Srini

  • How to run a servlet in tomcat 5.0.

    Hi all,
    how to run a servlet in tomcat 5.0
    please tell me the entire procedure....(directory structure)
    step by step....

    hi :-)
    http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Servlets.html
    or
    http://www.google.com.ph/search?hl=en&q=java+servlet+tutorial&btnG=Google+Search&meta=
    regards,

  • How to run a servlet in tomcat

    how i can run a servlet in tomcat?

    how i can run a servlet in tomcat?Don't try to do that yet; in your other thread you have shown that your are
    not capable yet of setting up a proper development environment.
    Take my advice, you can't walk or run yet so start with the basics.
    kind regards,
    Jos

  • How to call Servlet from jsp page and how to run this app using tomcat..?

    Hi ,
    I wanted to call servlet from jsp action i.e. on submit button of JSP call LoginServlet.Java file.
    Please tell me how to do this into jsp page..?
    Also i wanted to execute this application using tomcat.
    Please tell me how to do this...? what setting are required for this...? what will be url ..??
    Thanks.

    well....my problem is as follows:
    whenever i type...... http://localhost:8080/appName/
    i am getting 404 error.....it is not calling to login.jsp (default jsp)
    but when i type......http://localhost:8080/appName/login.do........it executes servlet properly.
    Basically this 'login.do' is form action (form action='/login.do').....and i wanted to execute this from login jsp only.(from submit button)
    In short can anyone please tell me how to diaplay jsp page using tomcat 5.5
    plz help me.

  • Just can't run HELLOWORLD servlet on Tomcat!

    Hi there, I worked with servlets all summer long and now I'm getting back to build one, and I'm totally confused... My problem's there :
    I try to run a simple HelloWorld servlet on Tomcat 4.1, and I get a 404 Error - Not found
    Well, here's the structure of my web application, contained in simpleservlet.war :
    WEB-APP
    -web.xml
    -CLASSES
    -servlet.class
    -LIB
    -servlet.jar
    Here's now the content of the web.xml file :
    <web-app>
         <servlet>
              <servlet-name>serv</servlet-name>
              <servlet-class>servlet</servlet-class>
         </servlet>
         <servlet-mapping>
              <servlet-name>serv</servlet-name>
              <url-pattern>/test</url-pattern>
         </servlet-mapping>
    </web-app>
    AND FINALLY here's how I invoke my servlet, I TRIED :
    http://localhost:1977/servlet/test
    AND ALSO
    http://localhost:1977/test
    AND BANG, I GET "ERROR 404 - NOT FOUND"
    A little help would be appreciated A LOT, well it's not supposed to be a hard problem... and by the way, I'm using port :1977, the problem's not there though.
    regards, Pierre

    Hi,
    First try http://localhost:1977 and see if you are getting Tomcat. As you said, this is not a problem. So, you should get the index.html of the Tomcat. Now, click on the one of the example. From the Address Bar, you will know the path of this example. Try putting your page at that location and then run.
    This should work.
    -- Ashish.

  • Exception "Cannot run program" while using ProcessBuilder class

    Hi Java-Folks,
    I try to start a program within a Java application using the ProcessBuilder class. This is the first time I use ProcessBuilder so I do not have any deep knowledge of it. Here is a snippet of my code:
    static void connectToHost(String Host) {
    ProcessBuilder pb = new ProcessBuilder("connect.exe"), Host);
    Map<String, String> env = pb.environment();
    env.put("SHELLWIDTH", "64");
    pb.directory(new File("C:\\MyProgram\\ExApp\\shell"));
    try (
    Process p = pb.start();
    } catch (IOException ex) {
    Logger.getLogger(ShellUtil.class.getName()).log(Level.SEVERE, null, ex);
    }Using this method I get an IOException which says *"Cannot run program "connect.exe" (in directory "C:\MyProgram\ExApp\shell"): CreateProcess error=2, The system couldn't find the specified file"*
    Does anybody have an idea why this is not working? I tried to start another application like "notepad.exe" and that works fine. So it seems related to the fact
    that the program I want to start is only available in a certain directory and not via the PATH env-variable.
    I would appreciate any help or hint :-)
    Regards,
    Lemmy

    Okay I guess I misinterpreted the JavaDocs regarding the directory method. The exception message is a little bit confusing too, because it seems like Java tries to find the Application within the specified
    working directory.
    I tried to use the full path with the ProcessBuilder constructor and it looks like this variant is working. I still have some trouble with the application itself but I was able to start another program which is
    not in the PATH var, using the full path to the executable.
    Thanks for the help so far.
    Bye
    Lemmy

  • How to run a servlet in Tomcat 5.0 server

    HI Everybody,
    I want to know how to run the servlet file on my tomcat 5.0 server. that is where to place a class file and deployment details.
    Thanks In ADVANCE

    Sourav_cs wrote:
    I am a biginner to start servlet i get confusion to configure servlet in tomcat 5 where it should be saved in tomcat directory and how to execute that as first timeHi,
    goto
    tomcat 5.0\webappsnow create a folder here. this is your webapplication project name. Let's suppose it as "TestApp"
    inside this create directories as follows :
    TestApp
            |
            |-----JSP/htmls( if you have any )
            |
            |-----WEB-INF(File Folder)
                       |
                       |-----web.xml
                       |-----lib ( Directory. place all the .jar files which are required for this project(if any) )
                       |-----classes ( .class files. )[all of your java code should be placed here.](servlets / beans/ pojo )this is the general Directory structure of a web application. now you've to place the compiled .class file of your servlet in the "TestApp\WEB-INF\classes" directory. make sure that you've configured the servlet in Deploment Desctiptor, i.e, web.xml.
    now start the server and type the url like : "http://localhost:8080/TestApp/TestServlet"
    the port no. 8080 is the default port no. of tomcat. you have to give your port no. if u've modified it. and TestServlet is the <url-pattern> of your servlet.
    go through some tutorials .. then you can easily know that
    Diablo

  • To Deploy a Servlet using Tomcat

    I am trying to deploy an example servlet in tomcat.
    my example servlet code is
    import javax.servlet.http.*;
    import javax.servlet.*;
    import java.io.*;
    public class HitServlet extends HttpServlet {
    private int mCount;
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String message = "Hits: " + ++mCount;
    response.setContentType("text/plain");
    response.setContentLength(message.length());
    PrintWriter out = response.getWriter();
    out.println(message); } }
    i 've placed my servlet in the directory
    webapps/midp/WEB-INF/classes/HitServlet.java
    i've successfully compiled the code. Then started the tomcat server & thro' IE tried to open the url to http://localhost:8080/midp/hits.
    but i 'm receiving the error the servlet bob is missing. i've placed the web.xml & server.xml in the folders specified in the tutorial. in server.xml i've added the code
    <Context path="/midp" docBase="midp" debug="0" reloadable="true" privileged="true"/>
    web.xml
    <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <servlet> <servlet-name>bob</servlet-name> <servlet-class>HitServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>bob</servlet-name> <url-pattern>/hits</url-pattern> </servlet-mapping> </web-app>
    If u can guide me to deploy the servlet it'll be very helpfull.
    With Best Regards
    Ramkumar

    one idea that I have is the CATALINA_HOME and CATALINA_BASE.
    We use CATALINA_BASE to install our stuff in another directory than that of the tomcat installation.
    in the tomcat-engine.log you should se sth similar to:
    2003-06-18 09:19:04 StandardHost[localhost]: Installing web application at context path /hits from URL file:<xxx/webapps/midp>
    2003-06-18 09:19:04 WebappLoader[/gtfn]: Deploying class repositories to work directory $CATALINA_BASE/work/Apache/localhost/gtfn
    ...

  • Tomcat 4.0 can run example but cannot run my servlet!

    I can run examples (both servlet and JSP) under Tomcat.
    Now I have servlets class file in
    C:\jakarta-tomcat-4.0.1\webapps\vpsystem\WEB-INF\classes\agent\bookmark\BookMark.class
    but I cannot see "http://localhost:8080/vpsystem/agent/bookmark/BookMark" in IE.It tell me no resource found.
    It's the matter of web.xml?It's the matter of server.xml?Or any another?
    Please someone help me out.
    Thanks!

    Maybe both. You should show how you have configured the web application in server.xml and the servlet in web.xml in order to be able to help you

  • Running servlet using Tomcat

    I have installed tomcat4.1.12..Ihave set up the environment variables also.
    set JAVA_HOME=C:\j2sdk1.4.0_02;
    set CATALINA_HOME=C:\jakarta-tomcat-4.1.12;
    PATH C:\WINDOWS;C:\WINDOWS\COMMAND;%JAVA_HOME%\bin;%JAVA_HOME%\lib;%CATALINA_HOME%\jakarta-tomcat-4.1.12\common\lib\servlet.jar;
    When i try to start tomcat its showing the following error .
    CATALINA_HOME ENVIRONMENT IS NOT DEFINED PROPERLY.
    Can anyone please tell me whats going on..?
    thanks in advance
    iby

    set JAVA_HOME=C:\j2sdk1.4.0_02;
    set CATALINA_HOME=C:\jakarta-tomcat-4.1.12;what are those semicolons doing there? Win2K (guessing from C:\ and backslashes) actually takes them as part of the environment variable. And your directories are probably not named "C:\j2sdk1.4.0_02;" and "C:\jakarta-tomcat-4.1.12;"???

  • Cannot make .war file using tomcat with eclipse and ant

    i have made all necesary configuration for deploying application using eclipse and ant for the tomcat server.
    when i start the server by clicking the tomcat icon on eclipse toolbar, the message is prompted that "missing application web.xml and using defaults". i have placed the web.xml file in the web/WEB-INF directory of the source project directory.
    also when i use ant by right-clicking on the build.xml file and choose Run as ant.. the process creates a desired .war file in webapps folder of the tomcat server but that war file does not works.
    where is the error i cannot figure out.
    am attaching the code of build.xml for reference.
    please help.
    build.xml:-
    <project name="BecilCTI" default="compile" basedir=".">
    <property file="build.properties"/>
    <property file="${user.home}/build.properties"/>
    <property name="app.name" value="BecilCTI"/>
    <property name="app.path" value="/${app.name}"/>
    <property name="app.version" value="0.1-dev"/>
    <property name="build.home" value="${basedir}/build"/>
    <property name="catalina.home" value="c:/Tomcat_5.5"/> <!-- UPDATE THIS! -->
    <property name="dist.home" value="${basedir}/dist"/>
    <property name="docs.home" value="${basedir}/docs"/>
    <property name="manager.url" value="http://localhost:8080/manager"/>
    <property name="src.home" value="${basedir}/src"/>
    <property name="web.home" value="${basedir}/web"/>
    <property name="compile.debug" value="true"/>
    <property name="compile.deprecation" value="false"/>
    <property name="compile.optimize" value="true"/>
    <!--<property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>-->
    <path id="compile.classpath">
    <!-- Include all elements that Tomcat exposes to applications -->
    <pathelement location="${catalina.home}/common/classes"/>
    <fileset dir="${catalina.home}/common/endorsed">
    <include name="*.jar"/>
    </fileset>
    <fileset dir="${catalina.home}/common/lib">
    <include name="*.jar"/>
    </fileset>
    <pathelement location="${catalina.home}/shared/classes"/>
    <fileset dir="${catalina.home}/shared/lib">
    <include name="*.jar"/>
    </fileset>
    </path>
    <target name="all" depends="clean,compile"
    description="Clean build and dist directories, then compile"/>
    <target name="clean"
    description="Delete old build and dist directories">
         <echo message="Cleaning all dirs."/>
    <delete dir="${build.home}"/>
    <delete dir="${dist.home}"/>
    </target>
    <target name="compile" depends="prepare"
    description="Compile Java sources">
    <!-- Compile Java classes as necessary -->
    <mkdir dir="${build.home}/WEB-INF/classes"/>
    <javac srcdir="${src.home}"
    destdir="${build.home}/WEB-INF/classes"
    debug="${compile.debug}"
    deprecation="${compile.deprecation}"
    optimize="${compile.optimize}">
    <classpath refid="compile.classpath"/>
    </javac>
    <!-- Copy application resources -->
    <copy todir="${build.home}/WEB-INF/classes">
    <fileset dir="${src.home}" excludes="**/*.java"/>
    </copy>
    </target>
    <target name="dist" depends="compile"
    description="Create binary distribution">
    <!-- Copy documentation subdirectories
    <mkdir dir="${dist.home}/docs"/>
    <copy todir="${dist.home}/docs">
    <fileset dir="${docs.home}"/>
    </copy> -->
    <!-- Create application JAR file -->
    <jar jarfile="${catalina.home}/webapps/${app.name}.war"
    basedir="${build.home}"/>
    <!-- Copy additional files to ${dist.home} as necessary -->
    </target>
    <target name="install" depends="compile"
    description="Install application to servlet container">
    <deploy url="${manager.url}"
    username="${manager.username}"
    password="${manager.password}"
    path="${app.path}"
    localWar="file://${build.home}"/>
    </target>
    <target name="list"
    description="List installed applications on servlet container">
    <list url="${manager.url}"
    username="${manager.username}"
    password="${manager.password}"/>
    </target>
    <target name="prepare">
    <!-- Create build directories as needed -->
    <mkdir dir="${build.home}"/>
    <mkdir dir="${build.home}/WEB-INF"/>
    <mkdir dir="${build.home}/WEB-INF/classes"/>
    <!-- Copy static content of this web application -->
    <copy todir="${build.home}">
    <fileset dir="${web.home}"/>
    </copy>
    <mkdir dir="${build.home}/WEB-INF/lib"/>
    </target>
    <target name="reload" depends="compile"
    description="Reload application on servlet container">
    <reload url="${manager.url}"
    username="${manager.username}"
    password="${manager.password}"
    path="${app.path}"/>
    </target>
    <target name="remove"
    description="Remove application on servlet container">
    <undeploy url="${manager.url}"
    username="${manager.username}"
    password="${manager.password}"
    path="${app.path}"/>
    </target>
    </project>

    So is context.xml actually overwriting the settings found in server.xml?I think so. The way I understand it is the the context.xml file saves you from having to edit server.xml. It is preferred for each web app to do its own config, rather than lumping them all together in server.xml.
    And what would be the best way to create the war file? IAt its heart, a WAR is just a zip file with its contents laid out in according to the specification of a web application directory structure.
    So the simplest way to make a war file is to zip up your directory structure with a tool like winzip, and rename it to be myApp.war.
    Regarding ant, I would recommend you take a look through [url http://jakarta.apache.org/tomcat/tomcat-4.1-doc/appdev/index.html
    ]this tutorial. It explains the basics of website layout, configuration and deployment.
    On [url http://jakarta.apache.org/tomcat/tomcat-4.1-doc/appdev/source.html] this page  in particular, it includes a link to a basic ant file that you can use as a starting point.
    Cheers,
    evnafets

  • Problem running simple servlet on tomcat 4.0

    hi,
    i have setup tomcat4.0 on the server and i am trying to run a simple servlet but it is not working. here is what i have done:
    1. setting the CATALINA_HOME variable to the directory where tomcat is installed
    2. setting the classpath variable to servlet.jar
    3. i am putting the .class fille in tomcat-home-directory/webapps/ROOTS/WEB-INF/classes
    4. i am giving the url as http://localhost:8080/servlet/HelloServlet.class
    but error is given...could you please tell where could i have probably made a mistake
    regards
    preeti

    hi tnguyen1973
    now my servlets are running on the server provided they are kept under /examples/WEB-INF/classes. But now i have my own folder at the same level of examples called Lm which also has WEB-INF/classes. but if i put my servlets here it is giving exception.hope u got me. please, tell me where should i make necessary modifications to get the servlets run from my own folder instead of examples
    thank u

  • Cannot run Disk Utility, use terminal, or boot from CD, all HDs locked

    I have a Mac Pro with 4 internal drives and 3 of them suddenly locked themselves. I can't run Disk Utility -- I get "underlying task reported failure on exit."
    I can't boot from Disk Warrior CD. I hold down the C key til the Apple logo appears, and then the computer just restarts into my regular system on my hard drive.
    I can run some apps from my startup drive, (obviously I can get on the internet). I downloaded Drive Genius but it will not install.
    I cannot use the terminal to try any of those fancy tricks I read about here.
    Here's what I get when I try Terminal:
    login: PAM Error (line 396): System error
    login: Could not determine audit condition
    [Process completed]
    And after that, I cannot type in the Terminal window.
    Man, this is crazy. 2 of my other internal drives have backup systems on them, but they will not show up as choices in the startup disk section of my system preferences - cuz they are locked.
    Any suggestions? I'm about to install a new drive and try and clone my working system on it and put Disk Warrior on it.

    DJWillis wrote:
    Wait, can I use Terminal from another computer in target mode?
    yes, but do you mean you can boot it in target mode but not from a DVD? this is very strange. try booting fro a DVD in a different way. reboot and hold "option" at the chime. this should boot you into startup disk manager. normally you can insert the DVd at the point and choose to boot from it.

Maybe you are looking for

  • K7T Turbo R Limited Edition and crackleing sound

    I started getting a crackling sound recently. I never had that problem before. The only thing I can think of that I have done that may have started it was to update the bios and the via chipset drivers. I tried to reinstall the 442 drivers (only the

  • Canon Pixma 922 constantly losing network connection

    I own a Canon Pixma 922 and from the very start I have been having issues with the netrworking staying connected. My network is a simple 3 computer connected to a D-link 655 router with WPS abilities. before this printer I had a very similar, older m

  • Firefox 14.01 and Flash 11.3 Issues

    I was previously having problems with Firefox 13 (forget which version specifically) after it updated with using Flash as many others were. I was excited to see that a v. 14 is now out and updated hoping it would solve my issues, but I am still havin

  • Is my set up sufficient?

    I'm soon going to buy a Sony HVR-Z1, primarily for underwater videography. I've got 2 questions that I could do with some advice on: 1) Is my current set up going to be sufficient to cope with HDV or is the G4 not going to be able to cope with it? 2)

  • 9i External Table Qs.

    I have a question: Say one of the file that the External table is pointing to, is being used (either being copied or edited), which creates a "LOCK transaction". DOes this mean that I can't do a SELECT statement on the External table because the sour