0

I wrote an HttpServlet and I named it "Stick" and then defined a Class named "John" in it. In addition, I wrote another HttpServlet and named it "StickDetails". Both of the Servlets are in the same package.

I want StickDetails servlet to function as a Main function (I want to use the "Stick" class inside it).

The problem starts when I try to write the command in StickDetails "John j = new John;" but john isen't recognized! (""String cannot resolved to a type"")

what did I do wrong here?

Here you see StickDetails servlet:

package wood;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class StickDetails extends HttpServlet{
    public void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws IOException,ServletException {


        Stick a; // Stick is not recognized "String cannot resolved to a type"

    }
}  

I am using Eclipse IDE for java Developers

Json
  • 655
  • 10
  • 27
  • Thanks Eddy but I need two different classes, I can't write it in the same one. – Json Nov 20 '14 at 23:05
  • In servlets, servlet container is responsible for instantiating the servlet. If You instantize a servlet object then you can't expect it work as servlet. – AsSiDe Nov 20 '14 at 23:20
  • This may help you http://stackoverflow.com/questions/3106452/how-do-servlets-work-instantiation-session-variables-and-multithreading – AsSiDe Nov 20 '14 at 23:21

1 Answers1

0

You Need To define a new class John, don't put it Stick Servlet. In your Stick Servlet you can create instance of John Class(if required) and after your logic, set attributes which are required in StickDetails Servlet and then use RequestDispatcher in Stick Servlet to forward request to StickDetails.

AsSiDe
  • 1,826
  • 2
  • 15
  • 24