File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Servlets (HelloWorld) & JBuilder Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlets (HelloWorld) & JBuilder" Watch "Servlets (HelloWorld) & JBuilder" New topic

Servlets (HelloWorld) & JBuilder

Steve Jensen
Ranch Hand

Joined: Sep 23, 2002
Posts: 126
Folks, I've some major problems regarding servlets.
I thought i'd give the first few chapters from a book on Servlets I have, a spin. The book's called "Java Servlet Programming Bible".
Anyway, I installed JRun 3.1
And my IDE is JBuilder 6 Enterprise edition.
Well, JRun is running.
And in JBuilder, I selected to start a new project (servlet), and copy the HelloWorld example from the book.
NOw folks, this is REALLY dumb, i admit, but the program won't compile, even when i've included the servlet.jar file.
The code is below:-
package servletbible.ch06.examples;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
* Hello World Servlet. Displays "Hello World" in the browser.
public class HelloWorldServlet extends HttpServlet

* Here we override the doGet method
* @param request the client's request
* @param response the servlet's response
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
* Sets the content type
PrintWriter out = response.getWriter();

* Prints the html document and Hello World!
out.println("<html><head><title>Hello World Servlet</title></head><body>");

public String getMessage()
return message;
} //End of HelloWorldServlet

And the errors I get when I try and compile the code are illustrated below:-
"": Error #: 300 : method getwriter() not found in interface javax.servlet.http.HttpServletResponse at line 9, column 31
"": Error #: 300 : variable message not found in class servletbible.ch06.examples.HelloWorldServlet at line 41, column 10
"": Error #: 901 : package . stated in source E:\Java\Servlets\test\ does not match directory test

Any ideas as to the problems, please, anybody?

John Bonham was stronger, but Keith Moon was faster.
chanoch wiggers
Ranch Hand

Joined: May 24, 2001
Posts: 245
you've specified the package incorrectly. Your code says
package servletbible.ch06.examples;
but it sounds like you are trying to put it into the test package and certainly looks like it from the error message

chanoch<p><a href="" target="_blank" rel="nofollow">Author of Professional Apache Tomcat</a></p>
Rajni Kumar

Joined: Mar 05, 2003
Posts: 8
Look at errors, it is giving in three java files.
the code u attached is the second one( look at your code. u have not defined varaible 'message'.
look at method, getMessage();
inside u are retruning message as string.
just add one line in ur code as follows:
String message = "HelloWorld";
and try.
All the best
I agree. Here's the link:
subject: Servlets (HelloWorld) & JBuilder
It's not a secret anymore!