Using other classes with Servlets


Web tier: servlets, JSP, Web frameworks: Using other classes with Servlets

  1. Using other classes with Servlets (2 messages)

    I am new to Servlets, and I was wondering if there was some trick to getting other classes to work with servlets, besides just putting them in the same directory. To clarify, say I have a servlet Servlet1, and I want to create an instance of a class myClass1, how do I do this? Currently I have Servlet1.class and myClass1.class in the same servlet directory, but when I try to declare an instance of myClass1 in Servlet1, Servlet1 crashes. Anyone that can give me a solution, it would be much appreciated!



    Threaded Messages (2)

  2. Using other classes with Servlets[ Go to top ]

    What server are you using? If you are new to servlets, I'm sure you're using something like Tomcat, right?

    Anyway, as long as the class is in the classpath, it should work. If you don't define a package, then the classes have 'default' access to the same directory.
  3. Using other classes with Servlets[ Go to top ]

    umm.. have you tried importing those packeges which you want to use?


    import java.sql.*;
    import com.mycompany.projectname.package.*;

    of course, you need to define those classes to belong to that package :

    package com.mycompany.projectname.package

    public class MyClass {