• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlets (HelloWorld) & JBuilder

 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.io.*;
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
*/
response.setContentType("text/html");
PrintWriter out = response.getWriter();

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

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

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

Any ideas as to the problems, please, anybody?
 
Author
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Look at errors, it is giving in three java files.
the code u attached is the second one(HelloWorld.java). 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic