Deploying my first servlet in tomcat

I have HTML form using get method as below
<HR><FORM method="GET" action="http://localhost:8080/Project/Formservlet"> and the Formservlet is in
project/Web-INF/classes
web.xml is in
project/Web-INF
set the context to Project directory in server.xml
The content of web.xml
<!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>Formservlet</servlet-name>
<servlet-class>Formservlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Formservlet</servlet-name>
<url-pattern>/Formservlet</url-pattern>
</servlet-mapping>
</web-app>but when i tried to submit the data of form it says
"The requested resource (/Project/Formservlet) is not available"
can anybody help me on this?

The class has to be in a package.
package project; //note it's a standard to have pkg names lower case.
public class FormServlet{
}Needless to say, when you put the class in a package project, the physical .java file has to be in a directory called 'project'.
And after you compile it, the .class file should be placed in the classes folder with the packaging. Thus your .class file ought to be in
<YOUR_WEB_ROOT>/WEB-INF/classes/project/FormServlet.classAnd finally your web.xml file should mention the fully qualified .class name - i.e
<servlet-name>Formservlet</servlet-name>
<servlet-class>project.Formservlet</servlet-class>ram.

Similar Messages

  • Running my first Servlet on TOMCAT - 10 duke dollars

    I am very new to Servlets. I am not creating a seperate context on Tomcat root to load the Servlet.
    I did the automatic installation of Tomcat 4.0.3 on windows NT available on <jakarta.apache.org/tomcat>
    I am going to load my servlet class in c:\<Tomcat Home>\Web Apps\Root\Web-inf\Classes
    But under my <Root\Web-inf> there is NO <Classes> subdirectory. So I created one and copied my class file there.
    Then on the browser, I typed
    http://127.0.0.1:8080/servlet/myFirstServlet
    Then I am getting the 404 Http Not found error.
    Error in detail is "/servlet/myFirstServlet" not found
    Can someone PLEASE help me ASAP.

    NOTE: I already sent this message under different heading.. I am sending this message under this for Mr/Mrs w234 ....
    Please let me know....
    I wrote my first Servlet with Forms, for a registration system. I have my input HTML file first.html and my java class (first.java) which processes the form and spits out the same information thru' the servlet.
    I added the line below in my server.xml in /conf directory, Forms is the subdirectory under webapps
    <Context path="/Forms" docBase="Forms" debug="0"
    reloadable="true" crossContext="true" />
    I created the web.xml as follows in c:<Tomcat home>\webapps\Forms\web-inf\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>first</servlet-name>
    <servlet-class>first</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>first</servlet-name>
    <url-pattern>/first</url-pattern>
    </servlet-mapping>
    </web-app>
    Note : My HTML file name and class files name both are same.. Also can someone tell me how to change web.xml for different HTML file name and class name ? Or do we have to include HTML file here in web.xml ?
    I am confused !!
    Then in the browser I typed
    http://127.0.0.1:8080/Forms/servlet/first.html
    I am getting this error
    Apache Tomcat/4.0.3 - HTTP Status 404 - /first.html
    type Status report
    message /first.html
    description The requested resource (/first.html) is not available.
    Can you please HELP ...
    Still I have not figure out how to give a couple of Duke s ? Please help me ...

  • Getting 104 resource not found error, when deploying my first servlet

    Hi,
    I am new to servlets, and after doing little home work i have created a small servlet but i am i getting http 104 resource not found error.
    steps i followed:
    1) installed pre-configured version of tomcat from http://www.coreservlets.com/Apache-Tomcat-Tutorial/.
    2)created new directory called ch1 under webapps, created WEB-INF under ch1
    3)included web.xml, classes in WEB-INF directly
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd"
    version="2.5">
    <servlet>
    <servlet-name>Ch1servlet</servlet-name>
    <servlet-class>Ch1servlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>Ch1servlet</servlet-name>
    <url-pattern>/servlet</url-pattern>
    </servlet-mapping>
    </web-app>
    4) included .class file under classes folder from following Ch1servlet.java file, I have set class path to point to servlet-api.jar file and jsp-api.jar and compliled following java file to get .class file which is included in classes folder
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    public class Ch1servlet extends HttpServlet
    public void doGet(HttpServletRequest request,HttpServletResponse response)throws IOException
    response.setContentType("text/html");
    PrintWriter out=response.getWriter();
    java.util.Date today=new java.util.Date();
    out.println("<html>"+
    "<body>"+
    "<h1 align=center>HF\'s Chapter1 Servlet</h1>"
    +"<br>" + today + "</body>" + "</html>");
    5) I am started tomcat server and when typed http://localhost( changed port from 8080 to 80), its giving tomcat page and not showing any error
    6) When i typed http://localhost/ch1/servlet/Ch1servlet, its giving http 404 error
    type Status report
    message: /servlet/Ch1servlet
    description: The requested resource (/servlet/Ch1servlet) is not available.
    7) i have uncommented(it comes preconfigured) the invoker part in web.xml.
    I have tried including servlet in an package and without package
    I am not sure if its problem with server configuration orelse problem with my file placing.
    Please let me know if you have any idea what went wrong.

    I found this, unable to copy it, so i am typing it:
    Feb11,2008 11:55:57 AM org.apache.catalina.core.AprLifecycleLIstener init
    INFO: The Apache Tomcat Native Library which allows optimal performance in production environemnt was not found on the java.library.path:c:\program Files\Java\jdk1.6.0\bin;....
    last line says
    org.apache.cataline.startup.catalina start
    INfo: Server startup in 657ms

  • 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
    ...

  • Deploying servlet on Tomcat using "ant install" not working. Please help.

    Hello. Normally I can find answers by using search, but I can't today for some reason. So please bare with me if this has been mentioned before. I will try to provide as much info as possible so that helping me isn't too much a chore. Thank you.
    I have downloaded and installed the JWSDP 1.3. and Tomcat is running. I am also using Ant 1.5.4 (previous installation - not one included with JWSDP) and modeled my build.xml file after the template provided here:
    http://jakarta.apache.org/tomcat/tomcat-5.0-doc/appdev/build.xml.txt.
    When I run ant on my respository, everything builds fine. But when I run Ant with the install target, I get the following error:
    BUILD FAILED
    file:C:/owl/build.xml:366: java.io.IOException: Server returned HTTP response co
    de: 401 for URL: http://localhost:8080/manager/deploy?path=%2Fowl&war=file%3A%2F
    %2FC%3A%5Cowl%2Fbuild
    Here is line 366 build.xml:
    localWar="file://${build.home}"/>
    ...which is included in this block for the target "install":
    <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>
    When I point my brower to the url located in the error verbose, I get the following:
    FAIL - Encountered exception java.lang.NullPointerException
    I am trying to get my environment set up correctly before I start spending time developing servlets, but I am getting tempted to just develop to servlets and "manually" installing/deploying them either by copying and pasting or by using the Tomcat manager. I would really like to do everything from Ant though if possible. Please help.

    I don't think this is at all correct:
    localWar="file://${build.home}"/>You've got to create a real WAR file - a JAR file with WEB-INF and all its minions inside it:
    http://access1.sun.com/techarticles/simple.WAR.html
    That's the file you need to refer to there. You can manage that with Ant too, of course.
    Here's what my Ant build.xml looks like for Web apps (there's a build-web.properties file that follows):
    build-web.xml
    <project name="Tomcat Build Tasks" default="clean" basedir=".">
        <target name="init-props">
            <tstamp>
                <format property="touch.time" pattern="MM/dd/yyyy hh:mm aa" />
            </tstamp>
            <filterset id="ant.filters">
                <filter token="DATE" value="${TODAY}" />
                <filter token="TIME" value="${TSTAMP}" />
            </filterset>
            <!-- Load in all the settings in the properties file -->
            <property file="build.properties" />
            <!-- Load in all Tomcat settings in the properties file -->
            <property file="build-web.properties" />
        </target>
        <target name="prepare" depends="init-props">
            <mkdir dir="${war.classes}"/>
            <mkdir dir="${war.lib}"/>       
            <mkdir dir="${manifest}" />
        </target>
        <target name="clean" depends="init-props" description="clean up temporary files">
            <delete file="${project}.war" />   
            <delete dir="${war.root}"/>
            <delete dir="${manifest}" />
        </target>
        <target name="set-tomcat-classpath" depends="prepare">
            <path id="tomcat.class.path">                  
                <fileset dir="${tomcat.home}/bin">
                    <patternset>
                        <include name="**/*.jar" />
                    </patternset>
                </fileset>
                <fileset dir="${tomcat.home}/shared/lib">
                    <patternset>
                        <include name="**/*.jar" />
                    </patternset>
                </fileset>
                <fileset dir="${tomcat.home}/common/lib">
                    <patternset>
                        <include name="**/*.jar" />
                    </patternset>
                </fileset>
                <fileset dir="${tomcat.home}/server/lib">
                    <patternset>
                        <include name="**/*.jar" />
                    </patternset>
                </fileset>
                <fileset dir="${ant.home}/lib">
                    <patternset>
                        <include name="**/*.jar" />
                    </patternset>
                </fileset>
            </path>              
        </target>
        <target name="create" depends="set-tomcat-classpath" description="create the war file">
            <!-- All files at root level -->       
            <!-- Temporarily put the JSPs at root until you figure this out -->
            <copy todir="${war.root}">
                <fileset dir="${src.jsp}"/>
            </copy>
    <!--
            <copy todir="${war.root}">
                <fileset dir="${src.html}" includes="*.html"/>
            </copy>
    -->
            <copy todir="${war.root}/css">
                <fileset dir="${src.css}"/>
            </copy>
            <copy todir="${war.root}/images">
                <fileset dir="${src.images}"/>
            </copy>
            <copy todir="${war.root}/js">
                <fileset dir="${src.js}"/>
            </copy>
            <!-- All files at the WEB-INF level and below -->       
            <copy todir="${war.web}">
                <fileset dir="${src.etc}" includes="web.xml"/>
            </copy>
            <!-- All files in the CLASSPATH lib -->
            <copy todir="${war.web}/lib">
                <fileset dir="${src.lib}" includes="**/*.jar" excludes="**/*-tests.jar, **/junit.jar"/>
            </copy>
            <!-- Put the dispatcher XML in WEB-INF/config -->
            <copy todir="${war.web}/config">
                <fileset dir="${src.etc}" includes="${project}-config.xml"/>
            </copy>
            <!-- Put XSL stylesheets in WEB-INF/xsl -->
            <copy todir="${war.web}/xsl">
                <fileset dir="${src.xsl}" includes="**/*.xsl"/>
            </copy>
            <!-- Put the project JAR file in WEB-INF/lib -->
            <copy todir="${war.web}/lib">
                <fileset dir="${deploy}" includes="**/${project}.jar"/>
            </copy>
            <!-- Create the manifest -->
            <buildnumber />
            <manifest file="${manifest}/manifest.mf">
                <attribute name="Implementation-Title"      value="${project}" />
                <attribute name="Built-By"                  value="${user.name}"/>
                <attribute name="Build-Date"                value="${TODAY}" />
                <attribute name="Major-Version"             value="${major}" />
                <attribute name="Minor-Version"             value="${minor}" />
                <attribute name="Build-Number"              value="${build.number}" />
            </manifest>
            <!-- Create the WAR file -->
            <jar jarfile="${project}.war"
                 manifest="${manifest}/manifest.mf">
                <fileset dir="${war.root}"/>
                <metainf dir="${src.etc}" includes="context.xml"/>
            </jar>
        </target>
        <target name="create-tomcat-admin-tasks" depends="set-tomcat-classpath">
    <!--
            <pathconvert targetos="windows" refid="tomcat.class.path" property="converted.class.path" />
            <echo message="CLASSPATH: ${converted.class.path}" />
    -->       
            <taskdef name="install"     classname="org.apache.catalina.ant.InstallTask"     classpath="tomcat.class.path"/>
            <taskdef name="remove"      classname="org.apache.catalina.ant.RemoveTask"      classpath="tomcat.class.path"/>       
            <taskdef name="reload"      classname="org.apache.catalina.ant.ReloadTask"      classpath="tomcat.class.path"/>
            <taskdef name="deploy"      classname="org.apache.catalina.ant.DeployTask"      classpath="tomcat.class.path"/>       
            <taskdef name="undeploy"    classname="org.apache.catalina.ant.UndeployTask"    classpath="tomcat.class.path"/>       
            <taskdef name="start"       classname="org.apache.catalina.ant.StartTask"       classpath="tomcat.class.path"/>       
            <taskdef name="stop"        classname="org.apache.catalina.ant.StopTask"        classpath="tomcat.class.path"/>       
            <taskdef name="list"        classname="org.apache.catalina.ant.ListTask"        classpath="tomcat.class.path"/>       
            <taskdef name="resources"   classname="org.apache.catalina.ant.ResourcesTask"   classpath="tomcat.class.path"/>       
            <taskdef name="roles"       classname="org.apache.catalina.ant.RolesTask"       classpath="tomcat.class.path"/>
        </target>
        <target name="install" depends="create-tomcat-admin-tasks" description="install the war file on Tomcat">
            <install    url="${tomcat.manager.url}"
                        username="${tomcat.username}"
                        password="${tomcat.password}"
                        path="/${project}"
                        config="file:/${basedir}/${src.etc}/context.xml"
                        war="file:/${basedir}/${project}.war" />
        </target>
        <target name="remove" depends="create-tomcat-admin-tasks" description="remove the war file on Tomcat">
            <remove     url="${tomcat.manager.url}"
                        username="${tomcat.username}"
                        password="${tomcat.password}"
                        path="/${project}" />
        </target>
        <target name="reload" depends="create-tomcat-admin-tasks" description="reload the war file on Tomcat">
            <reload     url="${tomcat.manager.url}"
                        username="${tomcat.username}"
                        password="${tomcat.password}"
                        path="/${project}" />
        </target>
        <target name="deploy" depends="create-tomcat-admin-tasks" description="deploy the war file on Tomcat">
            <deploy    url="${tomcat.manager.url}"
                        username="${tomcat.username}"
                        password="${tomcat.password}"
                        path="/${project}"
                        config="file:/${basedir}/${src.etc}/context.xml"
                        war="file:/${basedir}/${project}.war" />
        </target>
        <target name="undeploy" depends="create-tomcat-admin-tasks" description="undeploy the war file on Tomcat">
            <undeploy   url="${tomcat.manager.url}"
                        username="${tomcat.username}"
                        password="${tomcat.password}"
                        path="/${project}" />
        </target>
        <target name="start" depends="create-tomcat-admin-tasks" description="start an application on Tomcat">
            <start      url="${tomcat.manager.url}"
                        username="${tomcat.username}"
                        password="${tomcat.password}"
                        path="/${project}"/>
        </target>
        <target name="stop" depends="create-tomcat-admin-tasks" description="stop an application on Tomcat">
            <stop       url="${tomcat.manager.url}"
                        username="${tomcat.username}"
                        password="${tomcat.password}"
                        path="/${project}" />
        </target>
        <target name="list" depends="create-tomcat-admin-tasks" description="list all applications running on Tomcat">
            <list       url="${tomcat.manager.url}"
                        username="${tomcat.username}"
                        password="${tomcat.password}"/>
        </target>
        <target name="resources" depends="create-tomcat-admin-tasks" description="list all resources on Tomcat">
            <resources  url="${tomcat.manager.url}"
                        username="${tomcat.username}"
                        password="${tomcat.password}"/>
        </target>
        <target name="data-sources" depends="create-tomcat-admin-tasks" description="list all data sources on Tomcat">
            <resources  url="${tomcat.manager.url}"
                        username="${tomcat.username}"
                        password="${tomcat.password}"
                        type="javax.sql.DataSource"/>
        </target>
        <target name="roles" depends="create-tomcat-admin-tasks" description="list all user roles on Tomcat">
            <roles      url="${tomcat.manager.url}"
                        username="${tomcat.username}"
                        password="${tomcat.password}"/>
        </target>
    </project>
    build.properties
    # Properties file for setting up an Ant build.xml
    # Project specific items that change each time
    project=api-prototype
    major=1
    minor=0
    version=${major}.${minor}
    jar.name=${project}
    versiondate=${TODAY}
    # Directory structure (these should never change)
    bin=bin
    deploy=deploy
    doc=doc
    manifest=META-INF
    xml=xml
    # Everything under src should come out of a repository
    src=src
    src.bin=${src}/bin
    src.config=${src}/config
    src.data=${src}/data
    src.dtd=${src}/dtd
    src.java=${src}/java
    src.lib=${src}/lib
    src.profile=${src}/profile
    src.properties=${src}/properties
    src.schema=${src}/schema
    src.sql=${src}/sql
    src.templates=${src}/templates
    src.testdata=${src}/testdata
    src.xml=${src}/xml
    src.xsl=${src}/xsl
    # These are created and deleted by Ant each time
    javadocs=javadocs
    reports=reports
    output=output
    output.classes=${output}/classes
    output.lib=${output}/lib
    # Required for proper use of XDoclet
    xdoclet.home = C:/Tools/xdoclet-1.2b3
    build-web.properties
    war.root=war-root
    war.pages=${war.root}/pages
    war.web=${war.root}/WEB-INF
    war.classes=${war.web}/classes
    war.css=${war.web}/css
    war.js=${war.web}/js
    war.lib=${war.web}/lib
    war.tld=${war.web}/tld
    # Properties needed by Tomcat tasks
    ant.home =
    tomcat.home         =
    tomcat.manager.url  = http://localhost:8080/manager
    tomcat.username     =
    tomcat.password     = MOD

  • Fail to run my first Servlet with Sun ONE Studio 4 Update 1 (+ bi Tomcat)

    Hello !
    I failed to run my first Servlet with Sun ONE Studio 4 update 1 ( with built in Tomcat)
    I think that I followed most of the online instructions,
    so I successfully run a JSP file,
    but I failed with my first servlet:
    The error message is:
    "Standard Wrapper[:MyServlet]: Marking servlet MyServlet as unavailable
    javax.servlet.ServletException: Wrapper cannot find servlet class com.hemmerling.myservlet.MyServlet
    or a class it depends on
    So please don�t ask me for the code of the servlett ( simply taken from a book),
    but tell me why the one-and-only servlett was not found. what might I have done wrong, if I did everything I did to run the JSP file, too ?
    Of couse I copied the file into the "Classes" directory of the Webmodule ( WEB-INF ) and "processed" it, so that I was able to execute it.
    Any suggestions ?
    Tia
    Sincerely
    Rolf

    Tough to say, but try:
    1. Put the servlet in a package. If you're using the default package (class file in WEB-INF/classes directory, then Tomcat may not find it.
    2. Check out web.xml to ensure the <servlet> and <servlet-mapping> entries are correct.
    3. Make the servlet as simple as possible so you're sure that it is the servlet itself that cannot be found and not some other class that it uses.
    Good Luck

  • Need help getting first servlet to run in tomcat

    hi,
    i've complied my first servlet ok, using tomcat as server, problem is it can't find it. i up the class file under Web-inf/myApp under tomcat directory, typed:
    http://localhost:8080/myApp/TestingServlet
    in the url but it can't locate it. also i did start tomcat before going to url. can someone tell me what am i missing?
    Thank you.

    ok i got it to run but i had to create a classes dir under web-inf and had to use the url:
    http://localhost:8080/myApp/servlet/TestingServlet
    but why the servlet in the url, i don't have a servlet dir, does tomcat map classes dir to servlet dir?
    Thank you.

  • 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

  • Easy Step to Create Servlet in Tomcat x.x

    Hi to all,
    Lot of guys asking how to code / compile / deploy / run / etc.. in tomcat x.x.
    so
    Here is an step by step to create a simple servlet and deploy and run in tomcatx.x
    step 1:
    for ex:
         your CONTEXT path is
         c:\tomcatx.x\webapps\root     save your howtocode.java under c:\tomcatx.x\webapps\root\WEB-INF\classes\temp <folder>
    if (classes folder not found)
         create folder under WEB-INF \ classes (small letter)
    under classes dir > you to create temp (thats your package name);
    get into that dir
    c:\> cd c:\tomcatx.x\webapps\root\WEB-INF\classes\temp
    //compile
    c:\tomcatx.x\webapps\root\WEB-INF\classes\temp>javac -classpath "c:\tomcatx.x\common\lib\servlet-api.jar" howtocode.java -d "c:\tomcatx.x\webapps\root\WEB-INF\classes\temp" now class file will create and stored into c:\tomcatx.x\webapps\root\WEB-INF\classes\temp folder
    note: if you are using tomcat4.1 servlet.jar not servlet-api.jar , check it first by open your lib folder under tomcatx.x
    step 2
    open web.xml (under => c:\tomcatx.x\webapps\root\WEB-INF)
    add this code inside <web-app> </web-app>
         <servlet>
              <servlet-name>howtocode</servlet-name>
              <servlet-class>temp.howtocode</servlet-class>
         </servlet>
         <servlet-mapping>
              <servlet-name>howtocode</servlet-name>
              <url-pattern>/howtocode</url-pattern>
         </servlet-mapping>
    step 3
    Restart Tomcat server
    step 4
    open browser
    http://localhost:8080/howtocodehere is the servlet sample code
    howtocode.java
    package temp;
    import javax.servlet.ServletConfig;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;
    import javax.servlet.ServletException;
    import java.io.PrintWriter;
    import java.io.IOException;
    public class howtocode extends javax.servlet.http.HttpServlet
         //defining configuration in init ()
         public void init ( ServletConfig config) throws ServletException
              super.init( config );
         public void dotGet ( HttpServletRequest req, HttpServletResponse res ) throws ServletException, IOException
         doPost ( req,res );   // calling dopost inside doget
         public void dotPost ( HttpServletRequest req, HttpServletResponse res ) throws ServletException, IOException
              res.setContentType ( "text/html" );
              PrintWriter out = res.getWriter();
              out.println( "<html><body>" );
              out.println( "welcome from [email protected]" );
              out.println( "</body></html>" );
    }; //end of servletI hope it will help for servlet beginners

    I see you posting that kind of basic tutorials often. Why don't you start a website where you can save this information in? That's more worthful than posting it in a discussionforum.
    Anyway, there are silly typo's in the method names of the servlet. Futher on rather introduce separation in the business and view tiers than mixing them in one servlet.

  • Problems deploying a Web Service to Tomcat 5.5

    I am creating a J2EE 1.4 WebService using JDeveloper 10.1.3. Everything works fine while testing in the embedded OC4J server. When deploy the WAR file to Tomcat 5.5 everything goes haywire.
    I get the following error message:
    ===============================
    java.lang.reflect.InvocationTargetException
    at sun.reflect.GeneratedMethodAccessor30.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcce
    sorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at org.apache.tomcat.util.IntrospectionUtils.callMethodN(IntrospectionU
    ils.java:929)
    at org.apache.tomcat.util.digester.CallMethodRule.end(CallMethodRule.ja
    a:578)
    at org.apache.tomcat.util.digester.Rule.end(Rule.java:228)
    at org.apache.tomcat.util.digester.Digester.endElement(Digester.java:10
    7)
    at oracle.xml.parser.v2.NonValidatingParser.parseElement(NonValidatingP
    rser.java:1310)
    at oracle.xml.parser.v2.NonValidatingParser.parseRootElement(NonValidat
    ngParser.java:328)
    at oracle.xml.parser.v2.NonValidatingParser.parseDocument(NonValidating
    arser.java:295)
    at oracle.xml.parser.v2.XMLParser.parse(XMLParser.java:201)
    at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1561)
    at org.apache.catalina.startup.ContextConfig.applicationWebConfig(Conte
    tConfig.java:351)
    at org.apache.catalina.startup.ContextConfig.start(ContextConfig.java:1
    34)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConf
    g.java:260)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(Lifecyc
    eSupport.java:119)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:
    119)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBas
    .java:759)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:7
    9)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:809
    at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:69
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:47
    at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1190)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.jav
    :292)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(Lifecyc
    eSupport.java:119)
    at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBa
    e.java:1305)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.
    rocessChildren(ContainerBase.java:1569)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.
    rocessChildren(ContainerBase.java:1578)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.
    un(ContainerBase.java:1558)
    at java.lang.Thread.run(Thread.java:595)
    Caused by: java.lang.IllegalArgumentException: Invalid <url-pattern> TestWSSoap
    ttpPort in servlet mapping
    at org.apache.catalina.core.StandardContext.addServletMapping(StandardC
    ntext.java:2292)
    at org.apache.catalina.core.StandardContext.addServletMapping(StandardC
    ntext.java:2268)
    ... 31 more
    May 24, 2006 7:12:05 PM org.apache.catalina.startup.ContextConfig applicationWe
    Config
    SEVERE: Parse error in application web.xml file at jndi:/localhost/TestWebServi
    e/WEB-INF/web.xml
    java.lang.IllegalArgumentException: Invalid <url-pattern> TestWSSoapHttpPort in
    servlet mapping
    at org.apache.tomcat.util.digester.Digester.createSAXException(Digester
    java:2725)
    at org.apache.tomcat.util.digester.Digester.createSAXException(Digester
    java:2751)
    at org.apache.tomcat.util.digester.Digester.endElement(Digester.java:10
    0)
    at oracle.xml.parser.v2.NonValidatingParser.parseElement(NonValidatingP
    rser.java:1310)
    at oracle.xml.parser.v2.NonValidatingParser.parseRootElement(NonValidat
    ngParser.java:328)
    at oracle.xml.parser.v2.NonValidatingParser.parseDocument(NonValidating
    arser.java:295)
    at oracle.xml.parser.v2.XMLParser.parse(XMLParser.java:201)
    at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1561)
    at org.apache.catalina.startup.ContextConfig.applicationWebConfig(Conte
    tConfig.java:351)
    at org.apache.catalina.startup.ContextConfig.start(ContextConfig.java:1
    34)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConf
    g.java:260)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(Lifecyc
    eSupport.java:119)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:
    119)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBas
    .java:759)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:7
    9)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:809
    at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:69
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:47
    at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1190)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.jav
    :292)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(Lifecyc
    eSupport.java:119)
    at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBa
    e.java:1305)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.
    rocessChildren(ContainerBase.java:1569)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.
    rocessChildren(ContainerBase.java:1578)
    at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.
    un(ContainerBase.java:1558)
    at java.lang.Thread.run(Thread.java:595)
    May 24, 2006 7:12:05 PM org.apache.catalina.startup.ContextConfig applicationWe
    Config
    SEVERE: Occurred at line 14 column 23
    May 24, 2006 7:12:05 PM org.apache.catalina.startup.ContextConfig start
    SEVERE: Marking this application unavailable due to previous error(s)
    May 24, 2006 7:12:05 PM org.apache.catalina.core.StandardContext start
    SEVERE: Error getConfigured
    May 24, 2006 7:12:05 PM org.apache.catalina.core.StandardContext start
    SEVERE: Context [TestWebService] startup failed due to previous errors
    Please help.
    Thanks,
    Madhav

    Hi,
    This question came up recently on the JDeleloper forum too
    see web service deployed to outside of JDeveloper
    rgds
    Susan

  • Unable to deploy a simple servlet using WAR file

    Hi All,
    I am facing problem while deploying a simple servlet using WAR file on Oracle 9i App Server.
    I have installed Oracle 9i App Server. I referred following link to Deploy Applications Using WAR file:
         http://otn.oracle.com/products/ias/daily/sept12.html
    As mentioned in this documentation I have followed following steps to deploy WAR file:
    1] I have created a war file by name SimpleServlet.war. In SimpleServlet.war, there is a servlet by name Simple which prints time at which servlet was accessed.
    2] I have modified <ora9ias_home>\j2ee\home\config\application.xml and added following web module entry:
         <web-module id="SimpleServlet" path="../../home/applications/SimpleServlet.war" />
    3] To make this module accessible from over the web, I have modified file
         <ora9ias_home>\j2ee\home\config\default-web-site.xml and added following entry:
         <web-app application="SimpleServlet" name="SimpleServlet" root="/SimpleServlet"/>
    4] I saved both the files and started Oracle HTTP Server and accessed page as below:
              http://<server>:7777/SimpleServlet/Simple
    where Simple is servlet in SimpleServlet.war file.          
    In the browser, The page cannot be found is shown to user. I have verified that SimpleServlet.war is extracted to SimpleServlet folder under <ora9ias_home>\j2ee\home\applications folder. I found that Simple.class is stored under WEB-INF/classes folder and web.xml contains correct entry for url pattern for servlet Simple.
    What else could be the problem? Am I placing the war file in wrong place or modfiying application.xml or default-web-site.xml in a wrong directory?
    This is very urgent. Please help me with your valuable comments on this.
    Thanks in advance.
    Regards,
    Sandesh

    Hi Juliana,
    Thanks a lot for your suggestion.
    I am sorry if I have posted this message to a wrong forum. This is first time I am posting a message to OTN. I will resend message to J2EE forum as per you suggestion.
    Meanwhile, please note information you asked for is as below:
    I installed Oracle9iAS J2EE and Web Cache v9.0.3 on Windows 2000 server.
    It includes:
         - Oracle HTTP Server
         - Oracle9iAS Containers for J2EE
         - Oracle9iAS Web Cache
         - Oracle Enterprise Manager
    The release of installed Oracle9iAS is Release 2 (9.0.3)      
    Please do reply at the earliest.
    Once again thanks and look forward to hear from you.
    Regards,
    Sandesh

  • Help required in First Servlet

    Hey Guys.....I have read the above thread all posts and as this is also my first Servlet so I am also getting
    java.lang.ClassNotFoundException: servlets.HelloWorldServlet
    Now in my Apache tomcat folder C:\apache-tomcat-6.0.16\webapps\ServletExamples I have the WEB-INF folder.....which has the web.xml....
    Web.xml is something like this...
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <web-app 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"
         version="2.5">
         <servlet>
              <servlet-name>HelloWorldServlet</servlet-name>
              <servlet-class>servlets.HelloWorldServlet</servlet-class>
         </servlet>
         <servlet>
              <servlet-name>LoginServlet</servlet-name>
              <servlet-class>servlets.LoginServlet</servlet-class>
         </servlet>
         <servlet-mapping>
              <servlet-name>HelloWorldServlet</servlet-name>
              <url-pattern>/HelloWorldServlet</url-pattern>
         </servlet-mapping>
         <servlet-mapping>
              <servlet-name>LoginServlet</servlet-name>
              <url-pattern>/LoginServlet</url-pattern>
         </servlet-mapping>
    </web-app>The HelloWorldServlet.java is
    package servlets;
    import java.io.IOException;
    import java.io.PrintWriter;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    public class HelloWorldServlet extends HttpServlet{
         public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
              PrintWriter pw = response.getWriter();
              pw.println("<html>");
              pw.println("<head>");
              pw.println("</head>");
              pw.println("<body>");
              pw.println("<h3>Hello World as a Servlet</h3>");
              pw.println("</body>");
              pw.println("</html>");
    }and this is what I am writing on the url......
    http://localhost:8080/ServletExamples/HelloWorldServlet
    and I am assuming that the problem is coming in the <servlet-class> in the fully qualified name....
    So I decided to make a classes folder in the WEB-INF folder and copy all my .class files and .java files in it.....
    after this I am still getting the same error....
    java.lang.ClassNotFoundException: servlets.HelloWorldServlet
    and when I refresh it again it gives me a different error....which is
    type Status report
    message Servlet HelloWorldServlet is not available
    description The requested resource (Servlet HelloWorldServlet is not available) is not available.
    So how can anybody help me out in starting my carrier in the servlets...
    Thanks in advance
    Regards
    ISI

    Please can anyone suggest any good tutorials which can help me in this.....I am following this one but I am unable to overcome this error...
    http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Servlets.html
    Regards
    ISI

  • Problem with first servlet

    Hi
    I am trying to run my first servlet HelloWorld
    I have my servlet in the directory
    Tomcat 4.1/webapps/test/web-inf/classes/HelloWorld.class
    and my web.xml file in the directory
    Tomcat 4.1/webapps/test/web-inf/web.xml
    contains the following lines
    <web-app>
    <servlet>
    <servlet-name>HelloWorld</servlet-name>
    <servlet-class>HelloWorld</servlet-class>
    </servlet>
    <servlet-mapping>
         <servlet-name>HelloWorld</servlet-name>
    <url-pattern>/HelloWorld</url-pattern>
    </web-app>
    I also have changed the conf/server.xml file for the context as follows
         <Context path="/test" docBase="test" debug="0"
    reloadable="true" crossContext="true">
    and now when I try http://localhost:8080/test/servlet/HelloWorld
    Still I am getting the error status 404 The requested resource /test/servlet/HelloWorld not found.
    What am I doing wrong ????
    When I put my HelloWorld.class file in the webapps/examples directory it runs fine.WHy is it so ?
    Also for the above I have not started my tomcat server since I tried to run my HelloWorld from examples using http://localhost:8080/examples/servlet/HelloWorld it works perfect so I think I do not need to start server.
    Please reply me

    Try fully qualifying your servlet-class so that it reads something like this: <servlet-class>examples.servlet.HelloWorld</servlet-class>

  • How to Run servlet in Tomcat 5.5.9

    hi
    How to run servlet in tomcat 5.5.9?how to set context path in server.xml of conf folder in tomcat since there is no context tag in server.xml.
    Jiten

    Hi ! I have a similar problem, well, it's along the same line ...
    I'm using NetBeans 4.1, and i've coded a servlet. Using NetBeans to launch my servlet (with the bundled Tomcat 5.5.7) works fine, however i need to deploy my application unto a Tomcat 5.5.9 server.
    Thus, i copied the WAR file generated by NetBeans into the Tomcat 5.5.9 webapps directory, and Tomcat expands it.
    Problem is when i run my JSP pages with the form tags, they do not work on the Tomcat 5.5.9 environment. Anyone knows why?
    (These work on the NetBeans Tomcat bundle 5.5.7)
    My form action :
    <form name="index" method="get" action="PageServlet">
    My web.xml :
    <servlet>
    <servlet-name>PageServlet</servlet-name>
    <servlet-class>application.PageServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>PageServlet</servlet-name>
    <url-pattern>/PageServlet</url-pattern>
    </servlet-mapping>
    I'm really stumbed on why it doesn't work in Tomcat 5.5.9, any help is greatly appreciated, thanks in advance ^_^

  • Run servlet in tomcat 4.1

    Hi ,
    could someone please help me.
    Iam trying to run servlet in tomcat4.1 but in vain.
    please help

    hi
    If you want run a servlet in tomcat4.1,First write one html file,and servlet file.
    finally you need to write web.xml.this file will be placed in web-inf folder.
    You need to write this tags to run a servlet in tomcat 4.1
    <servlet>
    <servlet-name> name of the servlet</servlet-name>
    <servlet-class>class name of the servlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>name of the servlet</servlet-name>
    <url-pattern>/the ref name which u want call servlet</url-pattern>
    <servlet-mapping>
    Here the servlet name sholud be same .
    The url pattern name must match with the action attribute value in html.
    now you place your html file in root folder.
    place your servlet class file in classes folder.
    start ur browser type this http://localhost:8080/htmlfilename.

Maybe you are looking for

  • Mac won't start (Kernel Panics)

    Hello, My mac won't start up. It turns on, gets as far as the spinning circle and apple logo then a dark screen comes down with a Kernel Panic message. This occurred roughly three months ago and I ended up taking the mac into the regent street store

  • SP 2010 - Getting "An unexpected error has occurred. " message when accessing Sharepoint site after windows update - Windows 7 Home Premium

    Hi, I am new to SP 2010. I have installed Share point 2010 server (trial version) on my Windows 7 Home Premium Laptop by following the below link. http://msdn.microsoft.com/en-us/library/ee554869%28office.14%29.aspx Everything went fine and was able

  • Query on PO Deletion at Header Level

    Hello Everybody, We are using SRM 4.5 system (standalone without any MM backend). Our business needs to Delete POs which have already been ordered. Currently SAP is allowing us to delete the PO items once a PO is Ordered. But our requirement is to de

  • Vendor master data Postal code

    Hi, I am trying to create a new vendor in country Japan (JP). Postal code settings : Length 7 Rule 2 But when I am creating a Vendor with postal code of length 7, system is automatically adding a hyphen '-' in between and throwing an error message "P

  • How to implement Self Registration in EP 7.0

    Hello All, I am working in Enterprise Portal 7.0. I wanted to customize self registraion page in my portal in SAP Netweaver 7.0. Please tell me how to implement self registration in Portal 7.0. Thankx.