Where to place Servlets in Tomcat 4.0?

I just recently installed Tomcat on Win2000 and came across a little problem.
What is the directory in Tomcat 4.0 to place servlets in?
They seem to work fine if they are in 'examples' or in a package within the 'examples'-folder but they do not seem to work from ROOT or WEB-INF.
I tried creating a 'classes'-folder inside of 'WEB-INF'.
I have been trying to invoke them e.g. like this:
http://127.0.0.1:8080/servlet/test4.HelloWorldExample (where test4 is the package name)
I have re-started Tomcat everytime after changing something.
Where do you normally keep your servlets and how do you view them?
I would greatly appreciate a couple of real life examples.
Thanks in advance.

Are you sure that Tomcat is running properly? First
try http://localhost:8080
That should give you a Tomcat default page; otherwise you might have to check your classpath.
I just recently installed Tomcat on Win2000 and came
across a little problem.
What is the directory in Tomcat 4.0 to place servlets
in?
They seem to work fine if they are in 'examples' or in
a package within the 'examples'-folder but they do not
seem to work from ROOT or WEB-INF.
I tried creating a 'classes'-folder inside of
'WEB-INF'.
I have been trying to invoke them e.g. like this:
http://127.0.0.1:8080/servlet/test4.HelloWorldExample
(where test4 is the package name)
I have re-started Tomcat everytime after changing
something.
Where do you normally keep your servlets and how do
you view them?
I would greatly appreciate a couple of real life
examples.
Thanks in advance.

Similar Messages

  • Where to place javabeans in tomcat

    I have a problem finding my javabeans in apache tomcat 4. I have a project with jsp pages in a folder called crm. I have made some java beans which is in com.xxx.crm.beans package (folders). these folders (package) is placed in the crm folder and in my jsp page I use this code:
    <jsp:useBean id="ValidationBean" scope="session" class="com.xxx.crm.beans.ValidationBean" />
    <jsp:setProperty name="ValidationBean" property="*" />
    what am I missing out? I have also tried to restart tomcat. Do I have to place javabeans in the appservers classpath?
    Structure:
    crm/
    login.jsp
    crm/com/xxx/crm/beans/
    validationbean.class
    thanks in advance.
    nicolai

    thx :)
    I still run into problems. I have made the WEB-INF/classes folder and placed my folders and classes (com.xxx.crm.ValidationBean) in the project (jsp) folder. The message I get is:
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occurred at line: 1 in the jsp file: /crm/login.jsp
    Generated servlet error:
        [javac] Compiling 1 source file
    C:\jboss_tomcat\tomcat-4.1.x\work\Standalone\localhost\_\crm\login_jsp.java:42: cannot resolve symbol
    symbol  : class ValidationBean
    location: class org.apache.jsp.login_jsp
          ValidationBean ValidationBean = null;
          ^
    An error occurred at line: 1 in the jsp file: /crm/login.jsp
    Generated servlet error:
    C:\jboss_tomcat\tomcat-4.1.x\work\Standalone\localhost\_\crm\login_jsp.java:44: cannot resolve symbol
    symbol  : class ValidationBean
    location: class org.apache.jsp.login_jsp
            ValidationBean = (ValidationBean) pageContext.getAttribute("ValidationBean", PageContext.SESSION_SCOPE);
                              ^
    An error occurred at line: 1 in the jsp file: /crm/login.jsp
    Generated servlet error:
    C:\jboss_tomcat\tomcat-4.1.x\work\Standalone\localhost\_\crm\login_jsp.java:47: cannot resolve symbol
    symbol  : class ValidationBean
    location: class org.apache.jsp.login_jsp
                ValidationBean = (ValidationBean) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "ValidationBean");
                                  ^
    3 errorsValidationBean code:
    package com.xxx.crm;
    import java.io.*;
    import java.lang.*;
    import java.sql.*;
    import javax.sql.*;
    import javax.naming.*;
    import com.mysql.jdbc.*;
    // bean class
    public class ValidationBean implements Serializable {
      protected String username;
      protected String password;
      protected boolean validUser = false;
      private boolean isValidated = false;
      // constructor
      public ValidationBean() {
      }I use Borland JBuilder 8 Personal, and have compiled it there.

  • Where to place HTMl files in  tomcat while executing Servlets examples ?

    Hi,
    I'm learning servelets (HttpServlets). in that input is given through html files.now i dont know where to place that html file in apache tomcat server
    This is my Directry Structure
    Java's ---- C:\Program Files\Java\jdk1.5.0\bin
    Tomcat's--C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class ThreeParams extends HttpServlet
    public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException, IOException
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    String title = "Reading Three Request Parameters";
    String docType ="<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +"Transitional//EN\">\n";
    out.println(docType +"<HTML>\n" +"<HEAD><TITLE>" + title + "</TITLE></HEAD>\n" +"<BODY BGCOLOR=\"#FDF5E6\">\n" +"<H1 ALIGN=\"CENTER\">" + title + "</H1>\n" +"<UL>\n" +" <LI><B>param1</B>: "+ request.getParameter("param1") + "\n" +" <LI><B>param2</B>: "+ request.getParameter("param2") + "\n" +" <LI><B>param3</B>: "+ request.getParameter("param3") + "\n" +"</UL>\n" +"</BODY></HTML>");
    }HTML code ---
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML><HEAD><TITLE>Collecting Three Parameters</TITLE></HEAD>
    <BODY BGCOLOR="#FDF5E6">
    <H1 ALIGN="CENTER">Collecting Three Parameters</H1>
    <FORM ACTION="ACTION="C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\root\WEB-INF\classes.ThreeParams">
    First Parameter: <INPUT TYPE="TEXT" NAME="param1"><BR>
    Second Parameter: <INPUT TYPE="TEXT" NAME="param2"><BR>
    Third Parameter: <INPUT TYPE="TEXT" NAME="param3"><BR>
    <CENTER><INPUT TYPE="SUBMIT"></CENTER>
    </FORM>
    </BODY></HTML>
    {code}
    servlet code is compiling without any errors, now where should i place the class file and html file in tomcat to execute this program..                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    webapps\yourapplicationname\WEB-INF\

  • Where do u put servlets in Tomcat 4.1?

    Where do u put servlets in Tomcat 4.1? and how do you acces them?
    I've tried accesing SetMyCookie servlet (/myapp/WEB-INF/classes/SetMyCookie.java) using then following url:
    http://localhost:8080/myapp/servlet/SetMyCookie, but I keep getting a 404 error - The requested resource (/myapp/servlet/SetMyCookie) is not available

    Take a look at
    http://forum.java.sun.com/thread.jsp?forum=33&thread=373591&tstart=0&trange=15

  • How to run Servlet in TOMCAT

    I am new to Java Servlets. I am trying to run a servlet on TOMCAT but I don't know where to place my Servlet class file. TOMCAT works ok with sample jar file. Please guide.
    -- HTML code
    <HTML>
    <HEAD>
    <TITLE> Request Object </TITLE>
    </HEAD>
    <BODY>
    <FORM METHOD="POST" ACTION="/servlet/WelcomeServlet">
    Enter your Name: <INPUT TYPE=TEXT NAME="myName">
    <INPUT TYPE="SUBMIT" VALUE="Send Name">
    </FORM>
    </BODY>
    </HTML>
    -- Servlet Code
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.sql.*;
    public class WelcomeServlet extends HttpServlet {
    public void doPost(HttpServletRequest request,
    HttpServletResponse response)
    throws ServletException, IOException {
    String Name = request.getParameter("myName");
    PrintWriter out = response.getWriter();
    String mName = "test";
    try {
    mName = gName("AAA","VVV");
    catch (SQLException ex)
    out.println("SQLException");
    out.println("Welcome 1.1 " + Name + " !" + " mName " + mName);
    public String gName(String inputUserid, String inputPwd)
    throws SQLException{
    String vname = "Test";
    return vname;
    thanks
    Vineet

    I have Tomcat version 4.0 installed on my machine. If you look at the directory where you have Tomcat installed, you should find the directory structure:
    tomcat-folder/webapps/root/web-inf/classes
    Try placing your class files in the classes folder.

  • 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

  • Where to place oracle query?

    Hi,
    I have followed evnafets suggestions when setting up tomcat for connection pooling. Everything works fine when I place the query in the jsp, but I would like to do this correctly and keep all sql code out of the view.
    Where would I place the query, in a configuration file or would it go into a servlet ?
    Thanks,
    Alan
    Message was edited by:
    shadow_coder

    Thank you for your time, it is greatly appreciated by
    us new to java web-apps.
    ---warning --- beginning of rant ---
    It almost seems hopless, i'm not sure how anyone can
    possibly master or even learn all this,
    it wasn't enough to learn basic java, then learn how
    to use a servlet container (Tomcat 5.0), and then
    figure how to make it connect it to oracle9i, and
    seamlessly integrate this with the Apache2.0 web
    server. (I won't go into the Apache2.2 ordeal i had!)
    oh, then when you want to upgrade to Tomcat 5.5
    scratch everything you know, things are now
    different!
    I thought all I had to do now was learn just enough
    about jsp to use jstl with javascript for client side
    validation, or learn jsf and just bypass the whole
    javascript thing.
    now, I find out I probably should use Hybernate, but
    once I do this i'll find out Struts was the better
    way to go, or Spring would have suited my situation
    best.
    -- end of rant ---
    man, i needed to get that out, I feel much better :)
    AlanAmen brother. I'm travelling the same road you are to Java App development. I feel your pain. I think you've got the right mindset, however: As I continue to learn, one thing I've been cognizant of is keeping things in a logical place, decoupled as much as possible from other "pieces". This rule of thumb allows me to say "Okay, I'll probably learn a better way to do this on Wednesday, so if I keep things segmented, it'll be easy to switch pieces in and out."
    I doubt I'll ever get back to that "switch pieces in and out" phase, but it's good to know that it was organized as best as can be at the time of development. Keep the code comments in there, document as needed, test and test again. You'll be fine. :)
    Nice rant, by the way. You speak for me, too. :)

  • Invoking servlets in tomcat 4.1

    Hi..
    Regarding servlets and jsp i have some basic questions
    1. how to compile servelts , either with j2ee.jar of j2sdkee or servlet.jar of tomcat.
    2. where do i need to set the classpath, means either in environmnet variable or autoexec.bat or both, HOW TO SET THE CLASSPATH
    3. after successful compilation where to place the soruce code and class file, the exact location
    4. do i need to write my own web.xml file or do i need to modify the existing one, which one.
    5. what is the url i need to type in my browser.
    help will be appricated
    thanks in advance

    3. after successful compilation where to place the
    soruce code and class file, the exact locationAfter compilation, you don't need your source code. Class files should be placed in WEB-INF/classes, in their package folder.
    4. do i need to write my own web.xml file or do i need
    to modify the existing one, which one.
    If you write support classes (beans), you do not need to modify web.xml. If you write servlets, you need to modify your WEB-INF/web.xml file to map your servlet to your class:
        <servlet>
            <servlet-name>SomeServlet</servlet-name>
            <servlet-class>something.or.other.SomeServlet</servlet-class>
        </servlet>
       <servlet-mapping>
         <servlet-name>SomeServlet</servlet-name>
         <url-pattern>/servlet/SomeServlet</url-pattern>
       </servlet-mapping>
    5. what is the url i need to type in my browser.
    From example above: http://localhost:8080/servlet/SomeServlet or http://localhost:8080/your.jsp, assuming Tomcat runs on port 8080 and that you put your file under the ROOT context.
    >
    help will be appricated
    I think you should take a look at ant (http://ant.jakarta.org). It can help you automate most steps, from compiling, to copying files and making .war files.
    Hope this helps!
    Patrick

  • Error 404 running Servlet with Tomcat 4.1.18

    Hi,
    I made a small test servlet in a "hello world" style and I have problems to make it run under Tomcat 4.1.18 whereas it works perfectly on Tomcat 3.3 and Tomcat4.0.6...
    Why do I get a 404 error with 4.1.18 whereas I can reach the servlet on other versions of Tomcat ??
    Do you have an idea ?
    Is there some new tricks in 4.1.18 ?
    Thanks

    Here is my web.xml, i put it in the directory of tomcat\webapps\myApp\WEB-INF :
    <?xml version="1.0" encoding="ISO=8859-1"?>
    <!DOCTYPE web-app
         PUBLIC "-//Sun Microsystem, Inc.//DTD Web Application2.3//EN"
         "http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app>
         <servlet>
         <servlet-name>myservlet</servlet-name>
         <servlet-class>TestingServlet</servlet-class>
         </servlet>
    </web-app>
    and still it doesn't work...

  • 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

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

  • Newbie question about loading servlets on tomcat

    I have what is probably a very basic question about loading simple servlets on to tomcat to test its installation. I have followed instructions from numerous tutorials to the letter but still I can't get it to work.
    I have installed tomcat on win2k in c:\tomcat. I set up the jdk, environment vars (JAVA_HOME, CATALINA_HOME, TOMCAT_HOME) which all point at the correct dirs. I can compile a servlet without errors. I can also place a test jsp and html file into the root directory and they both work fine.
    However, now I am trying a test servlet and no matter what I do it gives me a 404. I have a servlet class file called "HelloServlet.class" which I placed into the %install_dir%\webapps\ROOT\WEB-INF\classes directory. I try to reference it using this url:
    http://localhost/servlet/HelloServlet
    Tomcat is configured to use port 80 and has been restarted after adding the servlet class file. Does anyone have a clue why this is not working for me?
    Many thanks
    Marc

    You have to add in the web.xml file that it is in the WEB-INF dir, the information about your servlet. An example:
    <web-app>
    <servlet>
    <servlet-name>HelloServlet</servlet-name>
    <servlet-class>HelloServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>HelloServlet</servlet-name>
    <url-pattern>/HelloServlet</url-pattern>
    </servlet-mapping>
    </web-app>

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

  • Unable to run servlet in Tomcat

    I've installed Tomcat and ran the examples fine, Ialso created some test jsp files and placed them in C:\tomcat\Tomcat-4.1\webapps\ROOT\test and then ran them calling http://localhost:8080/test/Hello.jsp which worked fine. When I place servlets into the same folder and call it, I get a 404. Do I need to set something in the web.xml file and if so please show and example.

    I've got a problem under Tomcat 4.1.27 - 5 . I wrote a Servlet and when I call it as an action in a form I get the message:
    The requested resource (/G2Mweb/marketing/inseriscicampagnaservlet) is not available.
    My web.xml contains the correct tags that define it:
    <servlet>
    <servlet-name>inseriscicampagnaservlet</servlet-name>
    <servlet-class>servlet.InserisciCampagnaServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>inseriscicampagnaservlet</servlet-name>
    <url-pattern>/inseriscicampagnaservlet</url-pattern>
    </servlet-mapping>
    Caller line in jsp file:
    <form action="inseriscicampagnaservlet" method="POST">
    I wrote other servlets that run without problems. The only difference between this and the others is that I created this in the wrong directory and then move it in /servlet.
    Any idea of what's happening?
    Thanks in advance
    Spinotto

Maybe you are looking for