You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Marc Wentink <Ma...@dsaict.nl> on 2006/02/16 15:37:56 UTC
How to install a simple servlet in Tomcat?
My excuses for such a simple question, but the archives are not =
searchable and the documentation not very clear. Or may-be I am just a =
terrible newbee.
Say I have a class file that contains a servlet, should not I do =
something so that tomcat becomes the container of this servlet, and a =
client browser could call the servlet? I expected to find some "install =
class file that contains the servlet so Tomcat becomes it container" =
option somewhere in the management part of Tomcat, but I am lost.
These are my files:
HelloIZ.java:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloIZ extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse =
response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out =3D response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Hallo IntraZis!</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Hallo IntraZis!</h1>");
out.println("</body>");
out.println("</html>");
}
}
I have got the class file after setting my classpath to servlet.jar and =
using javac.
And I thought I had to make some html to call the servlet:
StartServlet.html
<html>
<head>
<title>Hello Hospital!</title>
</head>
<body>
<a href=3D"./HelloIZExample">go</a>
</body>=09
</html>
Re: How to install a simple servlet in Tomcat?
Posted by Daniel Guggi <da...@gmail.com>.
Take a look at the servlet specification.
Basically you have to set up a context for your webapp. The web.xml file
describes your web-app. This means that you define your servlets and the
servlet-mapping (which urls will be mapped to which servlet) in web.xml
you could use something like this for your 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>myapp</display-name>
<servlet>
<servlet-name>HelloIZ</servlet-name>
<servlet-class>HelloIZ</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloIZ</servlet-name>
<url-pattern>/HelloIZExample</url-pattern>
</servlet-mapping>
</web-app>
This means that the URL: /HelloIZExample will be mapped to the HelloIZ servlet as defined in the <servlet> section.
hf!
On Thu, 2006-02-16 at 15:37 +0100, Marc Wentink wrote:
> My excuses for such a simple question, but the archives are not =
> searchable and the documentation not very clear. Or may-be I am just a =
> terrible newbee.
>
> Say I have a class file that contains a servlet, should not I do =
> something so that tomcat becomes the container of this servlet, and a =
> client browser could call the servlet? I expected to find some "install =
> class file that contains the servlet so Tomcat becomes it container" =
> option somewhere in the management part of Tomcat, but I am lost.
>
> These are my files:
>
> HelloIZ.java:
>
> import java.io.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
>
> public class HelloIZ extends HttpServlet {
>
> public void doGet(HttpServletRequest request, HttpServletResponse =
> response)
> throws IOException, ServletException
> {
> response.setContentType("text/html");
> PrintWriter out =3D response.getWriter();
> out.println("<html>");
> out.println("<head>");
> out.println("<title>Hallo IntraZis!</title>");
> out.println("</head>");
> out.println("<body>");
> out.println("<h1>Hallo IntraZis!</h1>");
> out.println("</body>");
> out.println("</html>");
> }
> }
>
> I have got the class file after setting my classpath to servlet.jar and =
> using javac.
>
> And I thought I had to make some html to call the servlet:
>
> StartServlet.html
>
> <html>
> <head>
> <title>Hello Hospital!</title>
> </head>
> <body>
> <a href=3D"./HelloIZExample">go</a>
> </body>=09
> </html>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: How to install a simple servlet in Tomcat?
Posted by David Delbecq <de...@oma.be>.
You must put the class in a .jar itself located in the WEB-INF/lib
folder of a .war or you must put the class in WEB-INF/classes of a .war
You must also setup your servlet un WEB-INF/web.xml
Then you must deploy you .war in tomcat (the easiest way is to use the
manager: http://tomcat.apache.org/tomcat-5.5-doc/manager-howto.html)
If you don't know what web.xml and what a .war are, i suggest you take a
look at http://java.sun.com/j2ee/tutorial/1_3-fcs/index.html section
about web technology.
Regards
Marc Wentink a écrit :
>My excuses for such a simple question, but the archives are not =
>searchable and the documentation not very clear. Or may-be I am just a =
>terrible newbee.
>
>Say I have a class file that contains a servlet, should not I do =
>something so that tomcat becomes the container of this servlet, and a =
>client browser could call the servlet? I expected to find some "install =
>class file that contains the servlet so Tomcat becomes it container" =
>option somewhere in the management part of Tomcat, but I am lost.
>
>These are my files:
>
>HelloIZ.java:
>
>import java.io.*;
>import javax.servlet.*;
>import javax.servlet.http.*;
>
>public class HelloIZ extends HttpServlet {
>
> public void doGet(HttpServletRequest request, HttpServletResponse =
>response)
> throws IOException, ServletException
> {
> response.setContentType("text/html");
> PrintWriter out =3D response.getWriter();
> out.println("<html>");
> out.println("<head>");
> out.println("<title>Hallo IntraZis!</title>");
> out.println("</head>");
> out.println("<body>");
> out.println("<h1>Hallo IntraZis!</h1>");
> out.println("</body>");
> out.println("</html>");
> }
>}
>
>I have got the class file after setting my classpath to servlet.jar and =
>using javac.
>
>And I thought I had to make some html to call the servlet:
>
>StartServlet.html
>
><html>
><head>
><title>Hello Hospital!</title>
></head>
><body>
><a href=3D"./HelloIZExample">go</a>
></body>=09
></html>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org