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.

Similar Messages

  • Problem in executing servlets under tomcat 4.1

    Dear Group,
    I am using Tomcat 4.1 and have the following directory structure:
    1.     C:\Tomcat 4.1\webapps\testapp
    ----It is my root directory and I have my html file called
    sample.html
    2.     C:\Tomcat 4.1\webapps\testapp\WEB-INF------web.xml is here
    3.     C:\Tomcat 4.1\webapps\testapp\classes\TestServlet.class
    -------here I have the servlet, no package---only one servlet
    My[b] web.xml has entry for:
    <?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>TestServlet</servlet-name>
            <servlet-class>TestServlet</servlet-class>
        </servlet>
        <servlet-mapping>
            <servlet-name>TestServlet</servlet-name>
            <url-pattern>/TestServlet</url-pattern>
        </servlet-mapping>
    </web-app>My[b] sample.html contains:
    <HTML>
    <BODY>
    <form method="post" action="http://localhost:8080/testapp/TestServlet">
    <input type=submit value="showServlet">
    <h2>
    <font color="green">First try on Serlvet</font>
    </h2>
    </form>
    </BODY>
    </HTML>Here is what I have done:
    1.     Started the Tomcat server
    2.     In the IE browser, I typed http://localhost:8080/testapp/sample.html
    -------- - the file shown correctly and I clicked the showServlet button.
    3.     I got the follow error �HTTP Status 404 - /testapp/TestServlet" the
    requested resource not availble
    4.     when I clicked the showServelt button the control goes to another page
    (as it should go to execute the servlet) .
    The URL is �http://localhost:8080/testapp/TestServlet�
    Please enlighten me where I went wrong?

    Hello all,
    Thank you for answering the question now the servlet gets executed.
    I here posts the steps i carried out to execute the
    servlet. If anyone have different idea pls post. Im
    pasting here the steps also attaching one.
    Steps to create your directory and work in Tomcat 4.1
    1.     Create your directory in Tomcat�s webapps Directory.
    -----If your tomcat is in d:\ the your directory may look
    ----- D:\tomcat\webapps\<your directory>
         ------E.g. �d:\tomcat\webapps\test�
    2.     In the test directory you can your html files directly or you can create a
    directory to hold html files.
         --------E.g. �d:\tomcat\webapps\test\first.html (OR)
    -------E.g. �d:\tomcat\webapps\test\html-files\first.html�
    3.     Create a folder called WEB-INF inside test
    -------E.g. �d:\tomcat\webapps\test\WEB-INF
    ------ Under the WEB-INF folder put your web.xml file
    4.     Create another folder named classes under the same test
    ----- E.g. �d:\tomcat\webapps\test\classes
    ----- Here you need to place your servlet classes
    ----- E.g. �d:\tomcat\webapps\test\classes\testServlet.class
    5.     Start any browser that are java enabled
    6.     Type �http://<machine name (or) IP add.>:8080/<your folder
    name>/<html file>�
    ----     E.g. http://localhost:8080/test/ html-files/first.html
    -----E.g.http://127.0.0.1:8080/test/html-files/first.html
    7.     Click the component (button, label�) to enable servlet
    8.     That�s all! Now you should get your servlet executed.
    Files:
    1.     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>testServlet</servlet-name>
        <servlet-class>testServlet</servlet-class>
      </servlet>
      <servlet-mapping>
        <servlet-name>testServlet</servlet-name>
        <url-pattern>/testServlet/*</url-pattern>
      </servlet-mapping>
    </web-app>
    2. first.html
    <html>
    <body>
    <form method="POST"
    action="http://localhost:8080/test/testServlet">
    <input type=submit value=click></input>
    </form>
    </body>
    </html>
    3. testServlet.java
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    public class testServlet extends HttpServlet
         public void doPost(HttpServletRequest req,
    HttpServletResponse res)throws      ServletException,
    IOException
              PrintWriter out = res.getWriter();
              out.println("<html>");
              out.println("<body>");
              out.println("<h1>Hello! </h1>");
              out.println("</body>"+"</html>");
    }I have put my first.html inside the folder
    �d:\tomcat\webapps\test\html-files\� and testServlet
    is under �d:\tomcat\webapps\test\WEB-INF\classes\� folder.

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

  • Steps to create f4 help for a table

    steps to create f4 help for a table

    These are the steps you have to take first:
    1. Please elaborate, your question does not all too clear.
    2. Search on SCN.
    3. Search on help.sap.com (for creating F4 search help).
    I guess you get the picture. Creating an F4 help is quite easy (you can find that on SCN for sure), but what do you mean by
    for a table
    1.Do you want to create a field which has an F4 help for searching tables or
    2. is this field part of a table and you need to have a search help for that field of that table in order to select some sort of value
    3. Is this a custom table.
    4. Is this a custom field for which F4 help should be added.
    5. Won't a domain value do.
    6. etc.

  • 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

  • Steps for creating custom doclet

    I'm a complete newbie to this whole JavaDoc Doclet stuff. I trying to create a custom Doclet I think. I want to use all the standard annotations but add 1 of my one aswell and a method so only the methods with my annotation is shown.
    I have a custom Doclet from the sun tutorial but don't have it creating a html file in docs folder or have it recognising any of the standard annotations. It doesn't extend or implement anything.
    Any advice on the step to take when creating a Doclet would be much appreciated.

    Thanks for the reply Leonid, still confused do.
    I'd like to create a HTML page that will show all the standard annotations/tags but also a custom tag. From the tutorial I have:
    import com.sun.javadoc.*;
    public class ListClass {
        public static boolean start(RootDoc root) {
             String tagName = "myTag";
             writeContents(root.classes(), tagName);
             return htmlDoclet.start(root);
             return true;
        private static void writeContents(ClassDoc[] classes, String tagName) {
             for (int i=0; i < classes.length; i++) {
                boolean classNamePrinted = false;
                MethodDoc[] methods = classes.methods();
    for (int j=0; j < methods.length; j++) {
         Tag[] tags = methods[j].tags(tagName);
              if (tags.length > 0) {
              if (!classNamePrinted) {
              System.out.println("\n" + classes[i].name() + "\n");
              classNamePrinted = true;
              System.out.println(methods[j].name());
              for (int k=0; k < tags.length; k++) {
              System.out.println(" " + tags[k].name() + ": " + tags[k].text());
    Should I be extending Standard or Doclet, I tried to extend Standard but it said it couldn't find myTag.
    I read a few places it's probably easier to just create the whole Doclet thing from scratch but is very time consuming and seems a bit daunting to me.
    I'm probably not making much sense but I'm a bit lost with all this.

  • Servlet on tomcat 4.1.18

    I am facing a problem of running servlets on Tomcat 4.1.18. The problem seems to be in the configuration. In the webapps folder, I created a folder greeting. In that, the WEB-Inf\classes folder has GreetingServlet.class.
    webapp\greeting has index.html that has to FORM ACTION set to /greeting/servlet/GreetingServlet.
    On clicking the submit button the message I get is that the resource /greeting/servlet/GreetingServlet is not found.
    Can anybody help in configuring the server so that the above mentioned servlet gets recognized?
    Thanks.
    Amitabh.
    [email protected]

    My application is located at %TOMCAT_HOME%\webapps.
    %TOMCAT_HOME%\webapps\greeting\WEB-INF\web.xml has the following:
    <web-app>
    <servlet>
    <servlet-name>greeting</servlet-name>
    <servlet-class>GreetingServlet</servlet-class>
    </servlet>
    </web-app>
    %TOMCAT_HOME%\webapps\greeting\index.html has the following:
    <FORM ACTION="/greeting/servlet/GreetingServlet" METHOD="POST">
    <P> Your name <INPUT TYPE="text" SIZE="40" NAME="name"></P>
    </FORM>
    Yet the problem persists.
    Have I missed some point?
    Help/assistance will be appreciated.
    Thanks.
    Amitabh.
    [email protected]

  • How to run Servlet in Tomcat 5.5.7 Server

    Hi,
    How to run Servlet in Tomcat 5.5.7 Server. I mean where I should copy my *.class file.
    Thanks in Advance.
    bbye.

    In order to complile the servlet you need to tell java where to find the servlet libary (as stated above by setting the class path). or (much easier IMO)
    copy the servlet-api.jar to
    JavaInstallDirectory\jre\lib\ext

  • Getting error 404 when iam running a simple login servlet in tomcat

    hi
    this is my Login.java
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    public class Login extends HttpServlet
         public void doPost(HttpServletRequest rq, HttpServletResponse rs)
              String username =rq.getParameter("username");
              String password =rq.getParameter("password");
    try{
              rs.setContentType("text/html");
              PrintWriter out=rs.getWriter();
              out.println("<html><body>");
              out.println("thank u, " + username + "you r logged sucessfully");
              out.println("</body></html>");
              out.close();
              }catch(Exception e){
                   e.printStackTrace();
    i have saved in the form ofC:\Program Files\apache-tomcat-4.1\webapps\sravan\WEB-INF\classes\Login.class
    where sravan is my folder
    step 2: Login.html
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <title>login page</title></head>
    <body>
    <h1> WELCOME TO THE SERVLET HOME PAGE</h1>
    ENTER UR USERNAME AND PASSWORD
    <form action="/sravan/Login" method="Post">
         username<input type="text" name="username" >
         password<input type="password" name="password" >
         <input type="submit" value="submit"></form>
         </body>
    </html>
    i have saved in the form C:\Program Files\apache-tomcat-4.1\webapps\sravan\Login.html
    step3:
    my 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>
    <display-name>beginning j2ee</display-name>
    <servlet>
    <servlet-name>Login</servlet-name>
    <servlet-class>Login</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>Login</servlet-name>
    <url-pattern>Login</url-pattern>
    </servlet-mapping>
    </web-app>
    i have saved in C:\Program Files\apache-tomcat-4.1\webapps\sravan\WEB-INF\web.xml
    step4:
    here is my server.xml
    <Context path="/sravan" docBase="sravan" debug="0" reloadable="true" privileged="true"/>
    saved in C:\Program Files\apache-tomcat-4.1\webapps\sravan\WEB-INF\server.xml
    everything is fine....program is compiled ...but when iam running the servlet in tomcat iam getting error 404 Login.html not found....
    so plz kindly help me this my first servlet .....

    There seems not to be any '.html' in your url-pattern
    <url-pattern>Login</url-pattern>- so i presume you should use
    http://yourhost/Logininstead.

  • How to create database in tomcat

    i am using net bean i want to know how to use mysql in tomcat
    what stuff i need to install for it . thank!!

    you don't create databases in tomcat. that's a servlet/jsp engine.
    install mysql, fire up the admin client, and create the database using that.
    %

  • Steps to create JCO to call R3 Function module in ISA CRM b2b webshop

    Hi experts,
    Can u help me in creating a JCo connection to R3 from CRM isa b2b webshop.
    See i am working on CRM 5.0 isa . I have a default jco connection calling to CRM.
    But i wanted an another JCO to call FM of R3.
    Can u pls give me the steps in creating this jco (XCM, Xml, changes etc )?
    Hope you have understood my question.
    Pls reply,
    thanks in advance,
    Niraja.

    Hi Niraja,
    The second option would be easy to do, as the connection is already made you can just use the connection pool.
    I feel maintaining/creating two connections would lead to performance issues.
    So its better to go with FM in CRM to FM in R/3
    If you want to go for a different connection or connection pool then follow this example
    In the world of database connectivity, creating individual connections to a database system is technically expensive and often incurs unwanted overhead in both client and server-side applications. Connection pools allow your application to check connections out from a pool and release a connection once the transaction has completed. This tip briefly explores the value and implementation of using connection pools in JCo.
    The following code presents two classes that demonstrate the use of a connection pool and its restrictions. You should be able to pull code from this example when adding pooling to your own Java/JCo application.
    The first JCo application does not use pooling:
    import com.sap.mw.jco.*;
    public class JcoTest {
    private static JCO.Client theConnection;
    private static IRepository theRepository;
    public static void main(String[] args) {
      createConnection();
      retrieveRepository();
      try {
      JCO.Function function = getFunction("RFC_READ_TABLE");
      JCO.ParameterList listParams = function.getImportParameterList();
      listParams.setValue("BSAUTHORS", "QUERY_TABLE");
      theConnection.execute(function);
      JCO.Table tableList = function.getTableParameterList().getTable("DATA");
      if (tableList.getNumRows() > 0) {
       do {
        for (JCO.FieldIterator fI = tableList.fields();
          fI.hasMoreElements();)
          JCO.Field tabField = fI.nextField();
          System.out.println(tabField.getName()
               + ":t" +
               tabField.getString());
         System.out.println("n");
       while (tableList.nextRow() == true);
      catch (Exception ex) {
       ex.printStackTrace();
    private static void createConnection() {
      try {
       theConnection = JCO.createClient("000", "DDIC", "minisap", "en", "sincgo", "00");
       theConnection.connect();
      catch (Exception ex) {
       System.out.println("Failed to connect to SAP system");
    private static void retrieveRepository() {
      try {
       theRepository = new JCO.Repository("saprep", theConnection);
      catch (Exception ex)
       System.out.println("failed to retrieve repository");
      public static JCO.Function getFunction(String name) {
        try {
             return theRepository.getFunctionTemplate(name.toUpperCase()).getFunction();
        catch (Exception ex) {
         ex.printStackTrace();
          return null;
    To add connection pooling you simply add this code to the beginning of the main method:
        if (connPool == null) {
          JCO.addClientPool(POOL_NAME,
                            5,
                            "000",
                            "bcuser",
                            "minisap",
                            "EN",
                            "sincgo",
                            "00");
    And replace the call to the createConnection() method with this:
             theConnection = JCO.getClient(POOL_NAME);
    The code should now look like this:
    import com.sap.mw.jco.*;
    public class JcoTest {
    private static JCO.Client theConnection;
    private static IRepository theRepository;
        private static final String POOL_NAME = "myPool";
    public static void main(String[] args) {
        JCO.Pool connPool = JCO.getClientPoolManager().getPool(POOL_NAME);
        if (connPool == null) {
          JCO.addClientPool(POOL_NAME,
                            5,      //number of connections in the pool
                            "client",
                            "username",
                            "paswword",
                            "EN",
                            "hostname",
                            "00");
            theConnection = JCO.getClient(POOL_NAME);
      retrieveRepository();
      try {
      JCO.Function function = getFunction("RFC_READ_TABLE");
      JCO.ParameterList listParams = function.getImportParameterList();
      listParams.setValue("BSAUTHORS", "QUERY_TABLE");
      theConnection.execute(function);
      JCO.Table tableList = function.getTableParameterList().getTable("DATA");
      if (tableList.getNumRows() > 0) {
       do {
        for (JCO.FieldIterator fI = tableList.fields();
          fI.hasMoreElements();)
          JCO.Field tabField = fI.nextField();
          System.out.println(tabField.getName()
               + ":t" +
               tabField.getString());
         System.out.println("n");
       while (tableList.nextRow() == true);
      catch (Exception ex) {
       ex.printStackTrace();
      JCO.releaseClient(theConnection);
    private static void retrieveRepository() {
      try {
       theRepository = new JCO.Repository("saprep", theConnection);
      catch (Exception ex)
       System.out.println("failed to retrieve repository");
      public static JCO.Function getFunction(String name) {
        try {
             return theRepository.getFunctionTemplate(name.toUpperCase()).getFunction();
        catch (Exception ex) {
         ex.printStackTrace();
          return null;
    Now, when this class executes, it will create a pool of 5 SAP connections. Once created, a single connection is retrieved and executed against. After the call to SAP has finished, the connections are released with:
    JCO.releaseClient(theConnection);
    You can easily integrate this code in any application that acts as a server or requires multiple users to access SAP via the Web.
    Regards,
    Sateesh Chandra

  • Steps to create Numer range buffering

    Hi Gurus,
    Can any b'dy explain the concept of number range buffering and also i need steps to create number range buffering for transactional data.
    here we have a full load it has to load 50L of records daily . it is taking 1.5 hr to 2 hr to load this data into an info cube we are looking to improve this load performence.
    thanks in advancde to all gurus.
    lax

    hi,
    Welcome to SDN...
    basically number range buffering is used to increase performance. usualy SID number range buffered,
    transaction rsrv can be used to check -> all elementary tests >> master data >> compare number range and max sid. and >> transcation data >> comparison of rumber range and max dimid.
    transaction SNRO is used to maintain number range.
    http://help.sap.com/saphelp_nw04/helpdata/en/7b/6eb2aa7aed44ea92ebb969e03081fb/content.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/95/3d5540b8cdcd01e10000000a155106/content.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/aa/dbc9b4b56143bb8f2ae909d7d040fa/content.htm
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/71efb490-0201-0010-949b-b2344b58b094
    Number Range Buffering can help cube loads if you your loads result in a good number of new Dim IDs being created with the load.
    Without buffering, each row of data to be loaded that would require a new Dim ID to be assigned (because it is new combination of characteristics for that dimension) must go out and read the Number Range table for that specific Dimension and get the next available number. So if you add 50,000 rows to a cube that results in 5,000 new Dim IDs to be assigned, that means 5,000 queries that must go read the table. Now if you buffered 500 numbers at a time, that would mean only 10 queries to the number range table.
    In a perfect BW world, someone in your shop would have the ability to go to your P system and make the change. Chances are, this ability is locked down and you will have to get the P opened to make the change.
    This can also make a big improvement in the load time if you are doing a large initial load of millions of rows to a cube.
    FOR MORE DETAILS http://www.sap-img.com/ge003.htm
    Re: SMS through SAP
    pls assign points if useful..
    -Shreya

  • Steps to create varients

    Hi
    Please Can anybody provide steps to create the varients for reports.
    Thanks in advance
    KP

    Hi KP,
    On the initial screen of transaction SE38 you have the radiobutton for variants.
    Enter your program name and Select the variant radiobutton. Then click on change (not create) button. It will take you to the screen for variant maintenance, where u enter the variant name and click create.
    Well, another easy way is execute ur program to view the selection screen , enter the values you want defaulted by way of the variant and click save.
    Hope this helps.
    Rgds,
    Aditya

  • 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

  • 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

Maybe you are looking for

  • How to check the row level security in TOAD for oracle

    Hi , for ex, i have 2 types of users normal user and super user super user can see the group set (some column name) created by normal user but normal user can not see the set created by super user this set crestion aslso has 3 types "U','P',S' P & S

  • MIGO Error- Order Unit & Order Price Unit

    Hi, I have a material whose base UOM is EA & alternate UOM is KG.(Conversion is maintained in the Material Master). I have created a PO for this material with order unit as EA & order price unit as KG. Now,when I try to do the GR using MIGO,I get the

  • File zipping

    Sender file adapter has to zip the files and provide password protected for the zip. Can this be achieved using PI. Thanks

  • Norton Antivirus = A Virus Itself?

    My laptop, aquired nearly three months ago, came with a free trial of Norton Antivirus. Nice enough, one might think. Over the course of time, I downloaded Mozilla Firefox and Windows Live Messanger. A month or so ago, the trial ended, and Norton was

  • HELP-Music Library doubled in storage

    I'm running out of space on my computer & the culprit is my music library & I think it is being double saved - somehow. In itunes my music library is 26.61 GB. But in the storage path: music:itunes:itunes music it is 54.49. I've checked the listing o