Tomcat/NetBeans problem.

H

Henry Fleming

Hi,
I'm wondering if anyone can help me.

I installed NetBeans IDE 3.5.1 (already have JDK 1.3.1) on Windows XP.

I created a simple HelloWorld servlet project. When I try to execute
it, the Progress Monitor says "The Tomcat server is not running
correctly" Then a browser comes up with the message "The browser
could not connect to the requested URL"

I tried typing "http://localhost:8080/servlet/HelloWorld" but it
didn't work.

Does anyone know what's wrong? This is not a good first impression of
NetBeans.

Thanks.
 
P

Paul K. Courtney

Did you start the tomcat server? I have JRun running on my laptop for
the servlet container, so I have to make sure that it is running before
a servlet will do anything.

Paul
 
G

Gavin Donald

To start Tomcat:

view => Runtime

Expand the 'Server Registry' , 'Installed servers' , 'Tomcat' ,
'localhost:8081' , 'defaultcontext' nodes.

Set the default context to where ever you saved your 'HelloWorld'
servlet by right clicking and selecting 'properties' then changing the
value of the 'docbase' attribute (This sets up the server so it knows
where the server root is).

In your docbase folder you should a set up a folder structure as
follows:

WEB-INF/classes

which is where Tomcat will look for your compiled class, your servlet
should go inside the classes folder, press F9 to compile inside of
NetBeans, you should now have a 'HelloWorld.class' file in your
'classes' folder.

In the folder 'WEB-INF' create a file called web.xml (this will tell
the server where your servlet is) and enter the following:


************* START COPY AND PASTE *******************


<?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>

<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>HelloWorld</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>

</web-app>


************* END COPY AND PASTE *******************

Without the copy and paste instruction, save it in the WEB-INF (should
be all uppercase) and call it web.xml

Go back to NetBeans right click on 'Internal Tomcat' and select
'Start'.

Open a web browser and type:

http://127.0.0.1:8081/hello

Note that in NetBeans the default port for Tomcat is 8081, also the
/hello part of that URL is defined in the web.xml file <url-pattern>
node. You should see your HelloWorld servlet.

The servlet I used to test these instructions is below (taken from
http://www.fluffycat.com/java/JavaNotes-HWServlet.html):

************* START COPY AND PASTE *******************

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

public class HelloWorld extends HttpServlet {

public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>HelloWorldServlet</title></head>");
out.println("<body><h1>HelloWorldServlet</h1></body>");
out.println("</html>");
}
}

************* END COPY AND PASTE *******************

Good luck !
Gav

Gavin Donald
http://www.prodia.co.uk
gav AT prodia DOT co 'DELETE THIS' DOT uk
 

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
474,262
Messages
2,571,054
Members
48,769
Latest member
Clifft

Latest Threads

Top