How to execute a servlet on  jakarta-tomcat-4.0.3

Please let me know how to execute a servlet on  jakarta-tomcat-4.0.3 .I am able to compile it .
Regards,
Saurabh Singhal

Hi
You must provide a mapping in your web.xml configuration file. This mapping will allow you to access servlet via url in form: "http://[domain]:[port]/[context]/servlet/[servlet full qualified name]"
This file should be located at $TOMCAT_HOME/conf.
Sample web.xml contains:
<web-app>
    <display-name>Sample Database App</display-name>
    <description>
     This is a simple application.
    </description>
    <servlet>
        <servlet-name>MyServlet</servlet-name>
        <servlet-class>MyServletImpl</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>MyServlet</servlet-name>
     <url-pattern>/myservletaddr</url-pattern>
    </servlet-mapping>
</web-app>
You can find more info at:
http://scitec.uwichill.edu.bb/cmp/online/CS36L/tutorials/TomcatIntroduction/TomcatIntroSampleApp.html
or
http://www.moreservlets.com/Using-Tomcat-4.html

Similar Messages

  • Help with running servlet with jakarta tomcat

    I had recently created a couple of java servlets and wanted to run them. I had put the .class files in Tomcat 4.1\webapps\Root\ then typed in http://localhost:8080/ then the servlet in the web browser. Here was the error page copied and pasted. If I put http://localhost:8080/servlet.class instead of http://localhost:8080/servlet I get a popup saying do I want to download the .class file. Theres probley a simple solution to this. Anyone know of any free hosts that will host servlets for free?
    HTTP Status 404 - /servlet
    type Status report
    message /servlet
    description The requested resource (/servlet) is not available.
    Apache Tomcat/4.1.18
    Thanks in advance
    George

    Hi I have the compiler jdk1.1.8 and wanted to upgrade my version. I downloaded the j2sdk1.4.1_01. I have the classpath set and everything. When I attempt to compile my java servlet it gives me an error but when I compile it with jdk1.1.8 it works.
    Isn't jakarta-tomcat-3.2.3 different compared the the one I have jakarta-tomcat4.1.18? Anyway thats what I read somewhere. The instructions you gave me do you think they are different because of us having different verions? I don't know if this is normal but whenever I startup my computer it just automaticly starts up tomcat server so when I put http://localhost:8080 it goes to the page saying I setup tomcat successfully. When I try to shutdown it doesn't do it.
    About the classpath. I thought i'm supposed to only put one path. So if I were to do that it would look like path set TOMCAT_HOME=C:\jdk1.1.8\Program Files\Apache Group\Tomcat 4.1 Thats how I would set it on my computer. I already installed and ran tomcat. I think your right I need to check the documentation correctly.
    Thanks in advance
    George

  • How to place a servlet file in Tomcat 5.0?

    Hi,
    i'm using Apache Tomcat 5.0 as myweb server.i don't know how to set the class path and where to place my servlet and html files,and how to run my servlet file.if anybody knows plz give me a detailed description abt this topic.

    Look at the directory structure of your Tomcat installation directory. You will see a webapps directory under that. The Tomcat installation comes with samples ready to run. Look at those and create a similar directory structure under webapps for your application. I don't think you need to worry about classpath. Tomcat should be taking care of all that if you create the proper directory structure.
    You run your servlet by specifying a url like:
    localhost:8080/servlets-examples/from a browser. This assumes that your installation is using port 8080 which I think is the norm for Tomcat. Here "servlets-examples" is the name of the directory you created. Actually Tomcat 5.0 comes with a "servlets-examples" application. This would be a good directory to look at. You could also run their examples to get a feel for it.
    If you are new to servlets, you'll probably have to get a book that explains how things need to be set up. You'll need to create a web.xml for your application. If you look at the servlets-examples directory under webapps, you'll see that it has a WEB-INF directory under it and that directory contains a file called web.xml as well as a sub-directory called classes. This structure is standard accross all application servers because it corresponds to the war (wars are specialized types of jars for web apps) file standard.

  • How to execute a servlet from a java code

    Hi,
              I am trying to make a URL connection to a particular site and trying
              to execute the servlet at the site specified and then storing the image
              pointed to by the servlet in a tmp location.I am passing the servlet id
              in the param Parameter.and the
              HTTP link in the URLString.
              This code worked fine with a CGI script but is not working
              properly with a servlet.
              A sample servlet code
              <img SRC=http://xyz/ABCServlet?imageKey=51752
              2881"/>
              private String executeServlet(String URLString, String param) {
              try {
              URL url = new URL(URLString);
              URLConnection connection = url.openConnection();
              connection.setDoOutput(true);
              PrintWriter out = new
              PrintWriter(connection.getOutputStream());
              out.println(param) ;
              out.close();
              BufferedReader in = new BufferedReader(new
              InputStreamReader(
              connection.getInputStream()));
              String inputLine;
              String inputData = "" ;
              while ((inputLine = in.readLine()) != null)
              inputData = inputData + inputLine ;
              in.close();
              System.out.println(inputData) ;
              return inputData ;
              Could anyone one help me out in this.
              Thanks,
              Trita
              

    Hi,
              I would assume your image is a binary file, and therefore you should use
              class for byteStream instead of charStream classes, i.e. Reader.
              Michael
              Trita Tripathi <[email protected]> wrote in message
              news:[email protected]...
              > Hi,
              > I am trying to make a URL connection to a particular site and trying
              > to execute the servlet at the site specified and then storing the image
              > pointed to by the servlet in a tmp location.I am passing the servlet id
              > in the param Parameter.and the
              > HTTP link in the URLString.
              > This code worked fine with a CGI script but is not working
              > properly with a servlet.
              > /*
              > A sample servlet code
              > <img SRC=http://xyz/ABCServlet?imageKey=51752
              > 2881"/>
              > */
              >
              > private String executeServlet(String URLString, String param) {
              >
              > try {
              > URL url = new URL(URLString);
              > URLConnection connection = url.openConnection();
              > connection.setDoOutput(true);
              >
              > PrintWriter out = new
              > PrintWriter(connection.getOutputStream());
              > out.println(param) ;
              > out.close();
              >
              > BufferedReader in = new BufferedReader(new
              > InputStreamReader(
              > connection.getInputStream()));
              > String inputLine;
              > String inputData = "" ;
              >
              > while ((inputLine = in.readLine()) != null)
              > inputData = inputData + inputLine ;
              >
              > in.close();
              >
              > System.out.println(inputData) ;
              > return inputData ;
              > }
              > Could anyone one help me out in this.
              >
              > Thanks,
              > Trita
              >
              >
              >
              >
              

  • How to execute jsp.servlet program in eclipse with small example

    This is sasidhar,
       How to set classpath pf tomcat to eclipse.
    and how to run jsp and servlets in eclipse 3.o
    thanks&regards
    sasidhar

    HI,
    Try these links
    http://help.sap.com/saphelp_nw04/helpdata/en/64/620a2ae361344abf47462809eb5388/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/f6/baba3eb645dc61e10000000a114084/frameset.htm

  • How to execute a servlet onload

    Hi everyone,
    I am very new to servlets. I have a jsp page that calls a servlet which is executed on a submit button within a form.
    It works, returning the data to the page. However I would like my servlet to be executed on load of the jsp. A tutorial that covers this area would be great.
    If you have a suggestion please post a response.. Thanks.
    <form name="data_form" method="post" action="Controller">
    <input type="hidden" name="action" value="getData"/ >
    </form>
    public void doPost(HttpServletRequest request, HttpServletResponse response)
         throws ServletException, IOException {
              //String action = request.getServletPath().substring(1, request.getServletPath().indexOf("."));
              String action = (String)request.getParameter("action");
              // select application logic
              String target = null;
              try {
                                   if(action.equals("getData")){                     
                        DataManager data = new DataManager();
                        request.setAttribute("Data", data.getData());
                        target = "/data.jsp";
                                     }catch(RuntimeException e){
                   e.printStackTrace();
              }Edited by: _AlyssaK on May 29, 2009 8:49 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Onload? I've had a laugh, seriously :)
    Create a Servlet class and implement doGet() wherein you do the desired loading tasks and finally forward the request to a JSP file and in the JSP file just access the loaded data through taglibs/EL. Finally map that servlet on an url-pattern and call it in your browser.
    E.g. (semi pseudo)
    doGet(request, response) {
        Data data = dataDAO.load();
        request.setAttribute("data", data);
        request.getRequestDispatcher("data.jsp").forward(request, response);
    }data.jsp
    <p>The data is: ${data}</p>web.xml
    <servlet-mapping>
        <servlet-name>yourServlet</servlet-name>
        <url-pattern>/data</url-pattern>
    </servlet-mapping>Then invoke it on [http://hostname:port/contextroot/data].

  • How to execute  servlets  in tomcat?

    Hi,
    I have compiled servlet file and tried to execute that file from root i.e. (http://localhost/'filename'....)as class file is in web-inf/classes.But it is executing from "http://localhost/servlet/" where is that servlet directory?
    why all servlets executes from "servlet/" directory?
    Please reply....
    Thanx in advance.

    I has the same problem, and my solution was to include a line in the tomcat-auto file foreach servlet i had.
    Under
    JkMount /MyApp/servlet/* ajp13
    I set a line
    JkMount /MyApp/MyServlet ajp13
    and in the web.xml of my webapp i included a servlet mapping for the servlet:
    <servlet>
    <servlet-name>MyServlet</servlet-name>
    <servlet-class>MyPackage.MyServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>MyServlet</servlet-name>
    <url-pattern>/MyServlet</url-pattern>
    </servlet-mapping>
    Then restarting tomcat and apache it worked.
    One question i have is that tomcat-auto file it is supposed to be auto-generated by tomcat, but in my case it is not, each time i add an app in the webapps dir i have to add all the stuff in tomcat-auto file. Does anyone know how to autogenerate this file?

  • How to execute CGI Programs in Tomcat Server

    Hi,
    I am working on executing Perl Scrtipts(or CGI programs) in Tomcat Server.
    I have downloaded ActivePerl 5.8.0 6.0.3 build.I have modified some .jar files in tomcat\server\lib.
    I have changed conf\web.xml to access the CGIServlet.class that is in servlets-cgi.jar.
    My example.cgi is
    #!c:\Perl\bin\perl.exe
    print
    "Content-type: text/plain\n\n";
    foreach $var (
    sort keys %ENV) {
    print
    "$var=\"$ENV{$var}\"\n";
    @values = split(
    /&/,$ENV{'QUERY_STRING'});
    foreach $i (@values) {
    ($varname, $mydata) = split(
    /=/,$i);
    print "$varname = $mydata\n";
    and my test.html is
    <HTML>
         <HEAD>
              <TITLE>Environment Variables using GET</TITLE>
         </HEAD>
         <BODY>
              <FORM ACTION="cgi-bin/example.cgi" METHOD="POST">
                   Press submit for a list of environment variables. <BR>
                   First Name: <input type="text" name="fname" size=30><p>
                   Last Name: <input type="text" name="lname" size=30><p>
                   <input type="submit">
              </FORM>
         </BODY>
    </HTML>
    here I have changed url mapping in web.xml to cgi-bin.
    The test.html produces two text fields first and last name on submit:
    it accesses:http://localhost:8080/smalltownpapers/cgi-bin/example.cgi?fname=Tim&lname=Eden
    this should print some environmental variables but it is producing an empty page.
    Tomcat is not showing any errors or Tomcat is not at all listening.
    Can any one help me to solve this and how to execute Perl scripts in Tomcat server
    Thanks,
    Regards
    Murthy

    Sorry, I've never done this. I went to the Tomcat site and pulled down the CGI docs, which you might have seen:
    http://jakarta.apache.org/tomcat/tomcat-5.0-doc/cgi-howto.html
    No other help available from me. Sorry.

  • How to execute and test servlets

    I wounder if smbd can explain me what software do I need to execute my servlet program. I'd like to test my first servlet on local machine. How to do that?
    thnks

    Erm to be more helpful...
    Tomcat is a servlet container freely downloadable from Apache. You will find it here:
    http://jakarta.apache.org/tomcat/index.html
    with documentation on how to use it.

  • How can i use my helloworld servlet in apache-tomcat-mod_jk?

    hi
    i copied
    helloworld.java helloworld.class
    to
    jakarta-tomcat-3.3.1/webapps/examples/WEB-INF/classes
    i can use example servlets in that directory by accessing localhost/examples/servlets
    and click links..(but if i type them in browser address bar, they dont' work either)
    what setting am i missing?
    thank you

    i didn't touch web.xml server.xml at all..
    i got this with logs files
    /usr/local/apache/logs/error_log
    [Thu Jul 25 14:14:00 2002] [notice] Apache/1.3.26 (Unix) PHP/4.1.2 mod_jk/1.1.0 configured -- resuming normal operations
    [Thu Jul 25 14:14:00 2002] [notice] Accept mutex: sysvsem (Default: sysvsem)
    [Thu Jul 25 14:19:19 2002] [notice] caught SIGTERM, shutting down
    [root@beautifulmind logs]#
    [root@beautifulmind logs]# cat mod_jk.log
    how does the link to jsp/servelt works and, not direct typing at address bar?
    mod_jk.conf
    <IfModule !mod_jk.c>
    LoadModule jk_module libexec/mod_jk.so
    </IfModule>
    JkWorkersFile "/usr/local/jakarta-tomcat-3.3.1/conf/jk/workers.properties"
    JkLogFile "/usr/local/jakarta-tomcat-3.3.1/logs/mod_jk.log"
    JkLogLevel emerg
    <Directory "/usr/local/jakarta-tomcat-3.3.1/webapps/examples">
    Options Indexes FollowSymLinks
    </Directory>
    JkMount /admin ajp13
    JkMount /admin/* ajp13
    JkMount /examples ajp13
    JkMount /examples/* ajp13
    #added by eugene
    JkMount /examples/servlet/* ajp13
    #added by eugene
    httpd.conf
    Include /usr/local/jakarta-tomcat-3.3.1/conf/auto/mod_jk.con

  • 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

  • How do I monitor Jakarta Tomcat?

    Hi:
    Please excuse me if this isnt the right forum to ask for this, but Im not sure where I should ask.
    Im trying to monitor resources (memory leak, cpu usage, etc) used by Jakarta Tomcat.
    I have tried RUE (http://rue.nolimits.ro) and JInsight (http://www.alphaworks.ibm.com/tech/jinsight) with no success (I think Jinsight only works for Websphere).
    Does anyone has been able to monitor Tomcat in any way?.
    Could you please tell me what you exactly used to do it?.
    I have seen this question in several forums (Tomcat Mailing List, IBM's Jinsight Forum, etc.) and still I cant find an answer.
    Help we'll be really appreciated!
    Regards.

    Hi
    It will be very useful if you get a tool like optimizeit (www.optimizeit.com). That will tell you whether it is a problem with servlet code or some bug in JVM or in Windows NT.
    Optimizeit Profiler would provide you with all the necessary information to investigate memory or performance issues across all EJBs, servlets, or JSPs. Similar Optimizeit guides are available, using the same Address Book J2EE application example, that describe how to troubleshoot two other important Java performance problem areas: Java memory leaks and speed bottlenecks due to poor CPU utilization
    bye all the best
    prashant

  • Should I install Apache Web server to use Jakarta Tomcat Servlet engine?

    Hello,
    I have some problems and now have a question:
    Should I install Apache Web server to use Jakarta Tomcat Servlet engine?
    JTK home page is available via http://localhost:8080
    Tomcat ver 3.1.3
    Thanks.

    No, you don't need to run Apache webserver (httpd) to run Tomcat. Tomcat by default runs on port 8080, but you can set it to any port, including 80, if you have permission to do so (on *nix systems, you need root permissions to run services on any port below 1024).
    Tomcat is a webserver as well, just one that includes a servlet container and JSP processor. So it will serve your html files, images, etc (aka static content), just as well as Apache httpd, in addition to being able to run servlets and JSPs.
    Apache httpd has more options for serving static content than Tomcat, so many people prefer to use it as their main webserver and only use Tomcat as a sort of "plugin" to handle servlets and JSPs. This can be achieved through a connector. Instructions on how to set this up are on the Jakarta website.
    So you could use Apache and Tomcat combined, next to each other, or totally separated. In many cases, just Tomcat will do.

  • 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 Can I Run Servlet in tomcat

    Hi My Friends
    Please can any one tell me how can I Run Servlet in tomcat using my own Virtual Directory � my ask about , what is the structure it must be make it in the hierarchy of the sub folder of Virtual Directory , and in watch folder it must be put the servlet files and there is any change it must be make it in any file of the tomcat files and so on
    Please give my full details about this thing
    And thanks

    What version of Tomcat are u using?

Maybe you are looking for