newbie - Servlets

X

Xarky

Hi,
I have just downloaded and installed Tomcat 5.0.30. I entered on
the link localhost:8080 and followed some links and examples provided
over there. The worked fine.

Now I would like to create my own servlets. Just to start off I am
trying a hello world program(I know that this is available). I am
trying the following code.

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class MyHelloWorld extends HttpServlet
{
public void init(ServletConfig c)
{
(c.getServletContext()).log("HelloWorld servlet initialized");
} // end method init

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>" + "My title" + "</title>");
out.println ("</head>");
out.println ("<body bgcolor=\"white\">");
out.println ("Hello World !!!!");
out.println("</body>");
out.println ("</html>");
} // end method doGet

} // end class MyHelloWorld

I saved this program with .java extension and compiled it succesfully.
Now what should I do to have access to it on my web browser.



Thanks in Advance
 
P

PerfectDayToChaseTornados

| Hi,
| I have just downloaded and installed Tomcat 5.0.30. I entered on
| the link localhost:8080 and followed some links and examples provided
| over there. The worked fine.
|
| Now I would like to create my own servlets.

<snip>
|
| I saved this program with .java extension and compiled it succesfully.
| Now what should I do to have access to it on my web browser.
|
|
|
| Thanks in Advance

Read the Tomcat application developers guide (Deployment section) here
http://jakarta.apache.org/tomcat/tomcat-5.0-doc/appdev/deployment.html

good luck
--
-P
"Programs that are hard to read are hard to modify.
Programs that have duplicated logic are hard to modify.
Programs with complex conditional logic are hard to modify"

( Kent Beck)
 
S

Steve Burrus

Hi "Newbie", you need to create/edit a deployment descriptor file or the
web.xml that is contained in Tomcat's WEB-INF folder under the servlets'
context folder.
 
G

Gerbrand van Dieijen

Xarky said:
Hi,
I have just downloaded and installed Tomcat 5.0.30. I entered on
the link localhost:8080 and followed some links and examples provided
over there. The worked fine.

It's much easier developing webapplications with an IDE. All the stuff
like deployment, packaging to webarchives, copy libraries is done
automatically.
I use JBuilder (Professional) for this. A demo can be downloaded from
the http://www.borland.com. You could also try others like Netbeans or
JavaOne (http://www.javasoft.com) or Eclipse (with possible plugins).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top