Tomcat 5.0.18 Servlets

I am new to JSP, installed J2SDK1.4.2_03 and Tomcat 5.0.18. I am able to get the jsp pages to work and also view the sample servlet examples. But I am having a hard time getting my servlets to work. I have
set the
ClassPath to C:\Jakarta\Jakarta-tomcat-5.0.18\common\lib\servlet-api.jar
My directory structure is
webapps\Myexamples\WEB_INF\CLASSES
WEB-INF has the web.xml doc, and the Classes and lib folders
Classes has the class called DontPanic, and the java file DontPanic
the url I typed is
http://localhost:8080/Myexamples/servlet/DontPanic
I get an error message source file not found.
Please help!!!!!!
Lakshmi

ClassPath to
C:\Jakarta\Jakarta-tomcat-5.0.18\common\lib\servlet-api
jarThis is worthless at runtime. Tomcat ignores your system CLASSPATH environment variable. It uses its own CLASSPATH at runtime. You must include the servlet-api.jar in your CLASSPATH when you compile. I do it by using the -classpath option. (Actually I use Ant to build Web apps.)
>
My directory structure is
webapps\Myexamples\WEB_INF\CLASSES
WEB-INF has the web.xml doc, and the Classes and lib
folders
Classes has the class called DontPanic, and the java
file DontPanic
So your serlvet DontPanic.class file is in webapps/Myexamples/WEB-INF/classes. (Not an underscore in WEB_INF, it's a hyphen WEB-INF.)
Tomcat won't deal with a class that's not in a package. You should put a package statement at the top of your servlet .java file and make sure that it's compiled into that directory in your WEB-INF/classes.
I'm assuming that you've got the servlet mapping in the web.xml properly. You should be mapping your servlet class DontPanic to a URL mapping /DontPanic.
the url I typed is
http://localhost:8080/Myexamples/servlet/DontPanic
After you've changed your WEB_INF to WEB-INF, try this URL:
http://localhost:8080/Myexamples/DontPanicAre there any messages in the Tomcat logs that tell you anything? - MOD

Similar Messages

  • Preventing Tomcat from destroying a servlet

    Hi,
    I'm looking for a way to prevent Tomcat from destroying a servlet.
    My problem is that I want to run parts of my application as a server that always needs to be running to receive requests from a legacy system. Is it possible to just start a thread from a dummy servlet that loads on startup and this thread will continue to run? Or will Tomcat destroy the servlet and the thread alongside?
    Thanks for any answers.

    I think it is one of the major weaknesses of the
    J2EE that you cannot have your own server code
    running in the same context.Huh? I' ve done that quite succesfully for years. Is there something that prevents it?
    You can't start your own threads within an EJB container. That surely does suck IMHO. But by "Tomcat" you mean a web server, not an EJB container, don't you?
    The last I read the Tomcat source, as far as I could figure, it destroyed servlet objects in exactly two situations: (1) when reloading a servlet when its code had changed, and (2) when shutting down the server. What I've done to prevent anything from being unloaded is put it in "library" jars; I don't think those are ever unloaded. AFAIK stuff loaded by the system class loader in particular is never unloaded. (I actually prefer to put servlets in CLASSPATH too, but that's ...controversial :-)

  • Tomcat doesn't find servlet

    (I apologize for the strange formatting of this message. I don't know exactly how to control it.)
    I'm trying to deploy a basic "Hello World" servlet into Tomcat (6.0.18) on Mac OS X Server (10.5.6).
    When I try to access it. I get 404 (not found) error.
    This is my web.xml file:
    <?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-app23.dtd">
    <web-app>
    <display-name>Hello World</display-name>
    <description>
    Just trying to get this to work.
    </description>
    <servlet>
    <servlet-name>hello</servlet-name>
    <description>
    Say hello.
    </description>
    <servlet-class>HelloWorld</servlet-class>
    <!-- Load this servlet at server startup time -->
    <load-on-startup>5</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>hello</servlet-name>
    <url-pattern>/</url-pattern>
    </servlet-mapping>
    <session-config>
    <session-timeout>30</session-timeout> <!-- 30 minutes -->
    </session-config>
    </web-app>
    I'm using a slightly modified build.xml file from apache.org. Muy build.properties file has the following info:
    # Context path to install application on
    app.path=/helloworld
    # Tomcat 6 installation directory
    catalina.home=/Library/Tomcat
    The servlet java source is pulled form the example servlets:
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class HelloWorld extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.println("<html>");
    out.println("<head>");
    out.println("<title>Hello World!</title>");
    out.println("</head>");
    out.println("<body>");
    out.println("Hello World!");
    out.println("</body>");
    out.println("</html>");
    When I deploy the web app via 'ant install', ant responds with:
    install:
    [deploy] OK - Deployed application at context path /helloworld
    The Tomcat Web Application manager shows an entry with a path of /helloworld, which links to http://eyemac.saintmarys.edu:8080/helloworld .
    Noticeably absent is the Display Name, which I have set to "Hello World" in web.xml.
    Clicking on the /helloworld link gives be a 404 error.
    I've tried things like setting the url-pattern to something like "/hi" then going to http://eyemac.saintmarys.edu:8080/helloworld/hi (or even http://eyemac.saintmarys.edu:8080/hi) but this still results in a 404 error.
    What am I doing wrong?
    I'll post my build.xml and server.xml files, if that would help.
    Thank you.
    Message was edited by: Steve Hideg

    If I put an index.html file in WEB-INF and redeploy the web app, I can access that web page via the link in the Tomcat Web Application manager at http://eyemac.saintmarys.edu:8080/helloworld/.
    I currently have the following servlet and servlet mapping in web.xml:
    <servlet>
    <servlet-name>hello</servlet-name>
    <description>
    Say hello.
    </description>
    <servlet-class>HelloWorld</servlet-class>
    <!-- Load this servlet at server startup time -->
    <load-on-startup>5</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>hello</servlet-name>
    <url-pattern>hi</url-pattern>
    </servlet-mapping>
    If I go to http://eyemac.saintmarys.edu:8080/helloworld/hi or (on the server) http://localhost:8080/helloworld/hi, I get a 404 error.
    And Tomcat Web Application manager still doesn't show this web app's Display Name.

  • How does one set databse parameters in Tomcat to run a servlet?

    Hi, I am trying to run a applet-servlet code, downloaded from the web. According to the installation instructions, the following is stated:
    Database Parameters. You can provide different database parameters to the servlet. These parameters are set during the administration of the servlet.
    dbDriver - name of the database driver class name (default = sun.jdbc.odbc.JdbcOdbcDriver)
    dbURL - complete database URL (default = jdbc:odbc:StudentDatabase)
    userid - user id (default = <none>)
    passwd - password (default = <none>)
    I am running TOMCAT on a Windows2000 machine. My question is how to does one set the parameters in TOMCAT. What is the default userid and password for TOMCAT.
    Any help/advise is appreciated in advance. Thanks.Regards.

    May be parameters must be set in web.xml in your war

  • IE, tomcat 4.0 - running servlet kicks to localhost7070 search screen

    I moved my shopping cart website (my first) to a PC running xp, downloaded j2sdk1.4.1_02 & tomcat4.0, set classpath, java_home, catalina_home. Set html in the webapps directory of Tomcat, java servlets in the webapps/mywebsite/WEB-INF/classes folder and recompiled sucessfuly. Tomcat runs on localhost7070, I can see the HTML in /mywebsite but when I click on the 'submit button' to run the servlet, my IE momentarily shows 'not found' but immediately goes to an ATT Worldnet site with a search field filled with localhost:7070.
    I have no idea of what setting might be off on IE but I have checked the directorys and system variables multiple times and can't figure this out. Any ideas would be greatly appreciated.
    Bruce

    Your web.xml (in WEB-INF) have your Servlet URL mapping. Try and see if you can get in contact with your Servlet manualy by typing in URLs like
    HTTP://localhost:7070/servlet/ProductLookup
    HTTP://localhost:7070/mywebsite/servlet/ProductLookup
    HTTP://localhost:7070/mywebsite/ProductLookup
    and when you find it, compare it the the URL in your HTML, relative to the URL used load the HTML page.

  • How to redirect all Tomcat request to a servlet

    How can I set up Tomcat to redirect all request to a certain sevlets which sends the user to the right web-application.
    What ever the user type in the URL, i.e.:
    http://customer01.myDomain.dk
    or
    http://customer02.myDomain.dk
    or
    http://customer01.myDomain.dk/myApp/login.jsp
    - I want tomcat to redirect to a servlet class. Is that possible?
    Thanks

    Yes but pretend each customer has more than one web-application. Then it is not possible for the customer to use only this URL:
    http://customer01.myDomain.dk
    Each customer need a seperate url for each application, something like this:
    http://customer01.myDomain.dk/myApp01/login.jsp
    http://customer01.myDomain.dk/myApp02/login.jsp
    ( easy URL�s they can remember )
    And I don�t think it is possible to make an alias to the exact URL to the web application. That�s why I need Tomcat to redirect all request to i.e. Index.jsp which then redirect to the correct application.
    Here is an example:
    Customer01 type in:
    http://customer01.myDomain.dk/myApp01/login.jsp
    Tomcat calls Index.jsp which redirect to this URL:
    http://www.myDomain.dk/myApp01_ID0921/login.jsp
    Can you help me with this problem?

  • How to retreive tomcat parameters in a servlet

    Hi guys&girls,
    I need to get username and password used to connect to a jsp application from a servlet. Is it possible? The application uses the standard j_security_check configuration on Tomcat (with the tomcat-users.xml file, containing users)
    I have to do it from the init method and not from doGet or doPost method.
    I know that could be a very simple answer (and I hope too...), but I couldn't find anything on the net :( (and those forum too, of course).
    Thanks in advance
    Claudio

    Because in the Init method the connection to database is performed.
    Now it is done using a .properties file, but I need to change it to use the same user/password of the tomcat application.
    Do you know if it is possible?It sounds like a really bad idea to me, for a variety of reasons.
    Ignoring for the moment the idea of tightly coupling your application security to a plaintext config file in your container, I'd reiterate that the servlet's init() method only gets called once. It sounds like you're asking how to use a single user's credentials (init() is called once, so you don't get a second chance at this) to connect to a database for the whole application. If that doesn't raise a gigantic red flag with you, it should. If you're using a service account to connect, I don't see any reason why you would find it necessary to specify those credentials in a container-specific config file.
    You may want to look into something like the Acegi framework to help you manage your application security.
    ~

  • Retrieve tomcat information in your servlet

    I have set a startup variable in CATALINA_OPTS, however i'm not very sure that it's actually been set and that tomcat has the variable.
    Is there a way to display such things in a servlet? Retrieve tomcat information? Get all variables, tomcat version, ... ...
    (in php there is a function called phpinfo() which displays a whole lot of information, is there an equivalent in java servlets/jsp?)
    Thanks in advance

    javax.servlet.ServletConfig
    javax.servlet.ServletContext
    java.lang.System.getProperties()
    There may also be vendor-specific (e.g. Tomcat) classes to obtain more information, but that should at least get you started.
    - Saish

  • Tomcat crashes while running servlet chat in IE

    Hi all!
    I've seen similar problems posted about three years ago, but I didn't see an answer for it.
    I'd be very grateful if you could help me.
    I'm writing a chat, the code was taken from the J.Hunter "Servlet programming book" O'reilly, "absurdly simple chat", and adjusted (I only need the Http version). It's an applet-servlet chat.
    When executed in IE, Tomcat crashes after a few (usually 5) sent messages. When executed in a debugger (I use Forte, the last available version, 4 update 1) the program works just fine...
    Another question is about debugging an applet, executed in a browser - how do I do this?
    Here is the code for the servlet:
    =================================
    import java.io.*;
    import java.net.*;
    import java.util.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class TryChatServlet extends HttpServlet
    // source acts as the distributor of new messages
    MessageSource source = new MessageSource();
    // doGet() returns the next message. It blocks until there is one.
    public void doGet(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException {
    res.setContentType("text/plain");
    PrintWriter out = res.getWriter();
    // Return the next message (blocking)
    out.println(getNextMessage());
    // doPost() accepts a new message and broadcasts it to all
    // the currently listening HTTP and socket clients.
    public void doPost(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException {
    // Accept the new message as the "message" parameter
    String message = req.getParameter("message");
    // Broadcast it to all listening clients
    if (message != null) broadcastMessage(message);
    // Set the status code to indicate there will be no response
    res.setStatus(res.SC_NO_CONTENT);
    // getNextMessage() returns the next new message.
    // It blocks until there is one.
    public String getNextMessage() {
    // Create a message sink to wait for a new message from the
    // message source.
    return new MessageSink().getNextMessage(source);
    // broadcastMessage() informs all currently listening clients that there
    // is a new message. Causes all calls to getNextMessage() to unblock.
    public void broadcastMessage(String message) {
    // Send the message to all the HTTP-connected clients by giving the
    // message to the message source
    source.sendMessage(message);
    // MessageSource acts as the source for new messages.
    // Clients interested in receiving new messages can
    // observe this object.
    class MessageSource extends Observable {
    public void sendMessage(String message) {
    setChanged();
    notifyObservers(message);
    // MessageSink acts as the receiver of new messages.
    // It listens to the source.
    class MessageSink implements Observer {
    String message = null; // set by update() and read by getNextMessage()
    // Called by the message source when it gets a new message
    synchronized public void update(Observable o, Object arg) {
    // Get the new message
    message = (String)arg;
    // Wake up our waiting thread
    notify();
    // Gets the next message sent out from the message source
    synchronized public String getNextMessage(MessageSource source) {
    // Tell source we want to be told about new messages
    source.addObserver(this);
    // Wait until our update() method receives a message
    while (message == null) {
    try { wait(); } catch (Exception ignored) { }
    // Tell source to stop telling us about new messages
    source.deleteObserver(this);
    // Now return the message we received
    // But first set the message instance variable to null
    // so update() and getNextMessage() can be called again.
    String messageCopy = message;
    message = null;
    return messageCopy;
    =============================
    The code for the applet is
    =============================
    import java.applet.*;
    import java.awt.*;
    import java.io.*;
    import java.net.*;
    import java.util.*;
    public class TryChatApplet extends Applet implements Runnable {
    TextArea text;
    Label label;
    TextField input;
    Thread thread;
    String user;
    public void init() {
    // Check if this applet was loaded directly from the filesystem.
    // If so, explain to the user that this applet needs to be loaded
    // from a server in order to communicate with that server's servlets.
    URL codebase = getCodeBase();
    if (!"http".equals(codebase.getProtocol())) {
    System.out.println();
    System.out.println("*** Whoops! ***");
    System.out.println("This applet must be loaded from a web server.");
    System.out.println("Please try again, this time fetching the HTML");
    System.out.println("file containing this servlet as");
    System.out.println("\"http://server:port/file.html\".");
    System.out.println();
    System.exit(1); // Works only from appletviewer
    // Browsers throw an exception and muddle on
    // Get this user's name from an applet parameter set by the servlet
    // We could just ask the user, but this demonstrates a
    // form of servlet->applet communication.
    user = getParameter("user");
    if (user == null) user = "anonymous";
    // Set up the user interface...
    // On top, a large TextArea showing what everyone's saying.
    // Underneath, a labeled TextField to accept this user's input.
    text = new TextArea();
    text.setEditable(false);
    label = new Label("Say something: ");
    input = new TextField();
    input.setEditable(true);
    setLayout(new BorderLayout());
    Panel panel = new Panel();
    panel.setLayout(new BorderLayout());
    add("Center", text);
    add("South", panel);
    panel.add("West", label);
    panel.add("Center", input);
    public void start() {
    thread = new Thread(this);
    thread.start();
    String getNextMessage() {
    String nextMessage = null;
    while (nextMessage == null) {
    try {
    URL url = new URL(getCodeBase(), "/servlet/TryChatServlet");
    HttpMessage msg = new HttpMessage(url);
    InputStream in = msg.sendGetMessage();
    DataInputStream data = new DataInputStream(
    new BufferedInputStream(in));
    nextMessage = data.readLine();
    catch (SocketException e) {
    // Can't connect to host, report it and wait before trying again
    System.out.println("Can't connect to host: " + e.getMessage());
    try { Thread.sleep(5000); } catch (InterruptedException ignored) { }
    catch (FileNotFoundException e) {
    // Servlet doesn't exist, report it and wait before trying again
    System.out.println("Resource not found: " + e.getMessage());
    try { Thread.sleep(5000); } catch (InterruptedException ignored) { }
    catch (Exception e) {
    // Some other problem, report it and wait before trying again
    System.out.println("General exception: " +
    e.getClass().getName() + ": " + e.getMessage());
    try { Thread.sleep(1000); } catch (InterruptedException ignored) { }
    return nextMessage + "\n";
    public void run() {
    while (true) {
    text.appendText(getNextMessage());
    public void stop() {
    thread.stop();
    thread = null;
    void broadcastMessage(String message) {
    message = user + ": " + message; // Pre-pend the speaker's name
    try {
    URL url = new URL(getCodeBase(), "/servlet/TryChatServlet");
    HttpMessage msg = new HttpMessage(url);
    Properties props = new Properties();
    props.put("message", message);
    msg.sendPostMessage(props);
    catch (SocketException e) {
    // Can't connect to host, report it and abandon the broadcast
    System.out.println("Can't connect to host: " + e.getMessage());
    catch (FileNotFoundException e) {
    // Servlet doesn't exist, report it and abandon the broadcast
    System.out.println("Resource not found: " + e.getMessage());
    catch (Exception e) {
    // Some other problem, report it and abandon the broadcast
    System.out.println("General exception: " +
    e.getClass().getName() + ": " + e.getMessage());
    public boolean handleEvent(Event event) {
    switch (event.id) {
    case Event.ACTION_EVENT:
    if (event.target == input) {
    broadcastMessage(input.getText());
    input.setText("");
    return true;
    return false;
    =====================================
    HttpMessage
    ======================================
    import java.io.*;
    import java.net.*;
    import java.util.*;
    public class HttpMessage {
    URL servlet = null;
    String args = null;
    public HttpMessage(URL servlet) {
    this.servlet = servlet;
    // Performs a GET request to the previously given servlet
    // with no query string.
    public InputStream sendGetMessage() throws IOException {
    return sendGetMessage(null);
    // Performs a GET request to the previously given servlet.
    // Builds a query string from the supplied Properties list.
    public InputStream sendGetMessage(Properties args) throws IOException {
    String argString = ""; // default
    if (args != null) {
    argString = "?" + toEncodedString(args);
    URL url = new URL(servlet.toExternalForm() + argString);
    // Turn off caching
    URLConnection con = url.openConnection();
    con.setUseCaches(false);
    return con.getInputStream();
    // Performs a POST request to the previously given servlet
    // with no query string.
    public InputStream sendPostMessage() throws IOException {
    return sendPostMessage(null);
    // Performs a POST request to the previously given servlet.
    // Builds post data from the supplied Properties list.
    public InputStream sendPostMessage(Properties args) throws IOException {
    String argString = ""; // default
    if (args != null) {
    argString = toEncodedString(args); // notice no "?"
    URLConnection con = servlet.openConnection();
    // Prepare for both input and output
    con.setDoInput(true);
    con.setDoOutput(true);
    // Turn off caching
    con.setUseCaches(false);
    // Work around a Netscape bug
    con.setRequestProperty("Content-Type",
    "application/x-www-form-urlencoded");
    // Write the arguments as post data
    DataOutputStream out = new DataOutputStream(con.getOutputStream());
    out.writeBytes(argString);
    out.flush();
    out.close();
    return con.getInputStream();
    // Converts a Properties list to a URL-encoded query string
    private String toEncodedString(Properties args) {
    StringBuffer buf = new StringBuffer();
    Enumeration names = args.propertyNames();
    while (names.hasMoreElements()) {
    String name = (String) names.nextElement();
    String value = args.getProperty(name);
    buf.append(URLEncoder.encode(name) + "=" + URLEncoder.encode(value));
    if (names.hasMoreElements()) buf.append("&");
    return buf.toString();
    Those files are the only files needed to execute the program.

    The whole Tomcat crashes, and no exception
    displayed.
    Do I have to write the log file, or it's kept by
    Tomcat itself?yes, tomcat writes a log file, you find it in the tomcat dir. but it's just very highlevel. Having a look in it could help.
    Is there a way to write a log file by myself?sure. you could get the log file from tomcat by getting it from the ServletContext:
    ServletContext = getServletContext();
    ServletContext.log("text to log");
    When I view the output window in Forte, it doesn't
    even write that Tomcat crashed.
    I use Tomcat that is installed with the last version
    of Forte(Sun 1 Studio, update 1), I guess it's the
    last version of Tomcat also.No. The lastest is 4.1.12 and i guess it's 4.0.4 with forte.
    Get Tomcat standalone from jakarta.apache.org and try to run your servlet with the standalone tomcat. this could help since i also expirenced problems sometimes with the forte-integrated tomcat.

  • Apache TomCat 6.0 - Generate Servlet Source Code

    sup java experts,
    does anyone know how I can view the Servlet source code that's generated by the JSP engine?

    lol...thanks. I know it sounds like a dumb question after having read your answer but I thought TomCat (by default) doesn't save the auto-generated .java files and that i'd have to turn on that feature somehow.
    Anyway, just to wrap up this question for future viewers, it turns out TomCat 6.0 does save the servlet source code generated by the JSP engine. I found mine in
    C:\web\Tomcat 6.0\work\Catalina\localhost\_\org\apache\jsp\marc\test_jsp.java
    Tomcat 6.0 = my installation folder
    marc = a folder I created under the "ROOT" directory (the folder where you put your .jsp files so that the server can find them)
    Thanks again njb7ty!

  • Tomcat can't run servlet /servlet tag help me please!

    do I config the web.xml file?

    Take a look at:
    http://java.sun.com/dtd/web-app_2_3.dtd
    It is the definition of what can be (and in what order) in a web.xml file for servlet specification 2.3 (ie: Tomcat 4.1).

  • Tomcat: How to run servlets in ROOT directory ?

    Hi,
    I am developing an app that has all JSP in ROOT directory.
    ROOT/appname/submodule/XXX.jsp
    How do I configure Tomcat so that I can place Servlets
    also in the same directory.
    (For better organization)
    i.e I would like to run as:
    http://host/appname/submodel/XXX.jsp
    and
    http://host/appname/submodule/YYY
    where YYY is the servlet YYY.class ??
    Is this doable ?

    Hi there,
    I am running into some trouble in configuring servlet directory other than the default /example/servlet/
    i am using tomcat3.2 with IIS as the webserver(NT 4.0).
    in the $tomcat_home/conf/server.xml, I added the following:
    <Context path="/myServletDir"
    docBase="E:/myServletDir"
    crossContext="false"
    debug="0"
    reloadable="true" >
    </Context>
    and i store my classes in
    E:/myServletDir/WEB-INF/classes/
    i even added a E:/myServletDir/WEB-INF/web.xml
    and tried to add something like this as suggested by some other people in tomcat forum:
    <servlet>
    <servlet-name>
    HelloWorldExample
    </servlet-name>
    <servlet-class>
    HelloWorldExample
    </servlet-class>
    </servlet>
    i stopped tomcat and restart, still can't make it work:
    http://myhost/myServletDir/servlet/HelloWorldExample
    or
    http://myhost/myServletDir/HelloWorldExample
    it would then tell me files not found. but if i put any classes in the examples/WEB-INF/classes, they would be just fine...
    what should I do? please help...
    thanks in advance,
    ann

  • Tomcat /manager commends from Servlet

    Hi all,
    I asked a question regarding the excution of Tomcat /manager commands from a servlet and I got no replies... :(
    Well, I never found a way to directly execute the /manager commands from the servlet (API) - but I did (eventually) get it working via URLConnection. Now, I've decided to release my (simple) code here so that it may help others!
    This code searches for a context and then checks if it is running, if it is found not to be running it will attempt to start it. (tested and found to work under Tomcat 5.0.28).
      String
        protocol  = "http",
        host      = "localhost",
        usr       = "usr",
        pwd       = "pwd",
        context   = "/myapp";
      int port = 80;
      URL list = new URL(protocol,host,port,"/manager/list");
      URLConnection c = (URLConnection)list.openConnection();
      String encs = new sun.misc.BASE64Encoder().encode((usr+":"+pwd).getBytes());
      c.setDoInput(true);
      c.setRequestProperty("Authorization", "Basic " + encs);
      c.connect();
      BufferedReader buf = new BufferedReader(new InputStreamReader(c.getInputStream()));
      String line;
      while ( (line = buf.readLine()) != null )
         * Search for the /workpackages context
        if ( line.startsWith(context+":") )
           * Found the context
           * Now make sure that it's running
          if ( line.indexOf("running") > 0 )
             * Context /workpackages found to be running!
              System.out.println("Context ["+context+"] - Running!");
          else
             * Context found NOT to be running!
             * Try and start the context!
            buf.close();
            System.out.println("Context ["+context+"] - Attempting to start context...");
            URL start = new URL(protocol,host,port,"/manager/start?path="+context);
            c = (URLConnection)start.openConnection();
            c.setDoInput(true);
            c.setRequestProperty("Authorization", "Basic " + encs);
            c.connect();
            buf = new BufferedReader(new InputStreamReader(c.getInputStream()));
            while ( (line = buf.readLine()) != null ) System.out.println(line);
          break;
    notes:
    The buffer reading after both commands seems to be required! I don't know why... But I found that without them, the manager commands seem to be ignored!?!? odd!
    Well, I hope this helps someone...

    thanx
    but when i am Deploying directory or WAR file located on server
    where is this XML Configuration file,
    so that i can fill in the text box-XML Configuration file URL
    and secondly in tomcat 5.5.4
    there is no context path described in server.xml
    so where is this in 5.5.4

  • Tomcat wont shutdown because servlet is active

    At the intial invokation of the servlet, the servlet spawn severals threads (all child threads extends TimeTask) to perform specific tasks and sleep until the time interval is up, and perform the task again...and so on.
    After createring and starting the children threads, the servlet goto sleep for 24 hours
    while (true){
    try{    Thread.sleep(HOUR_24); }
    catch (InterruptedException e){}
    According to Tomcat API, Tomcat allow the servlet to finsh perform it task before shutting down....however, my servlet will never finish....it's up 24 hours a day, 365 days a year.
    Currntly, we have to manually find the servlet and kill the process.
    Is there some way I can get the servlet to unload itself when Tomcat shut down?

    your thread:
    class ABCThread extends Thread {
      public static final long TIME_24_HOURS = ..... ;
      public boolean running = true;
      public synchronized run() {
          while(running) {
                try { wait( TIME_24_HOURS ); } catch (InterruptedException ex) { return; }
                ... your database stuff is here ...
      }your servlet:
      ABCThread abcThread = new ABCThread(); // this is your running thread instantiated by this servlet
      public void destroy() {
             synchronized(abcThread) {
                    abcThread.running = false;
                    abcThread.notifyAll();
    ...This trick is to "notify" the sleeping thread ABCThread. If it notified, InterruptedException will be thrown from the wait( ) , you can use this to jump out from the looping..
    If the notifyAll() happens while the thread is not wait()ing, then the thread would exit as soon as it encounter the next while(running) condition.
    Does this solve?
    rgds,
    Alex

  • Tomcat can't find servlet class

    Hello,
    I am trying to forward information from a jsp page to a servlet (the example in JSPIntro.pdf). I keep getting the error that the servlet class can't be found. I have put it in webapps/examples/web-inf/classes. I also added the servlet name in several web.xml files in different directories to no avail. Can anyone give me a hint on setup.
    Thanks

    to setup correctly the servlet you need something like this int the web.xml
    <servlet>
    <servlet-name>yourservlet</servlet-name>
    <servlet-class>xx.yyy.zzz.yourservlet</servlet-class>
    <init-param>
    </servlet>
    and you must put the class under
    WEB_INF/lib/xx/yyyy/zzz directory of your context.
    the servlet must be called as
    http://yourhost/yourcontext/servlet/yourservlet
    hope it helps,
    Giovanni

Maybe you are looking for