Wrox Home  
Search P2P Archive for: Go

  Return to Index  

servlets thread: question about servlet in a package


Message #1 by "zhebincong" <zhebincong@1...> on Thu, 3 Jan 2002 02:18:59
--------------23347D630599288F9AB8B14A
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

try to call the servlet like this

http://127.0.0.1:8080/ee/servlet/hi.Hello

when u put package in servlet, u need to call by using the package name infront
the servlets name.

zhebincong wrote:

> hello
> i use tomcat4.0,and write a simple servlet "Hello.java",put it
> in "C:\jakarta-tomcat-4.0\webapps\ee\WEB-INF\classes",i
> input "http://127.0.0.1:8080/ee/servlet/Hello",the code works well,but
> after i add a package declaration "package hi;" in front of my servlet,and
> put it in "C:\jakarta-tomcat-4.0\webapps\ee\WEB-INF\classes\hi\",wheather
> i input "http://127.0.0.1:8080/ee/hi/servlet/Hello"
> or "http://127.0.0.1:8080/ee/servlet/hi/Hello",both of them don't work,why?
> and how can i call a servlet that is in a package from the browser? thanks!
>
> my code:
>
> package hi;
> import java.io.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
>
> public class Hello extends HttpServlet{
>         public void service(HttpServletRequest req,
>                              HttpServletResponse resp)
>                 throws IOException,
>                         ServletException{
>                 resp.setContentType("text/html");
>                 PrintWriter out=new PrintWriter(resp.getOutputStream());
>                 out.print("<html>");
>                 out.print("<body>");
>                 out.print("hello world!");
>                 out.print("</body>");
>                 out.print("</html>");
>                 out.close();
>         }
> }
>



  Return to Index