Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie Question! Help Compiling java servlet. 1

Status
Not open for further replies.

aswolff

Programmer
Jul 31, 2006
100
US
Hi Folks:

I am trying to compile/run the below java servlet. We are using websphere 6.0.2.19.

1. How can I deploy a single java class like the one below?

2. When I try to compile with:
'javac HelloServlet.java' I get error:
Code:
HelloServlet.java:16: cannot resolve symbol
symbol  : class HttpServlet
location: class HelloServlet
public class HelloServlet extends HttpServlet

I think above error is related to me not specifying the correct classpath to imported classes. But how am I suppose to know the right classpath to use?

Thanks!!!

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

public class HelloServlet extends HttpServlet 
{
  public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException, IOException 
  {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    String docType = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
                     "Transitional//EN\">\n";
    out.println(docType +
                "<HTML>\n" +
                "<HEAD><TITLE>Hello</TITLE></HEAD>\n" +
                "<BODY BGCOLOR=\"#FDF5E6\">\n" +
                "<H1>Hello World</H1>\n" +
                "</BODY></HTML>");
  }
}
 
Thanks. That helped.

My next question is...in order to make my servlet calleable I need to mess around with web.xml file? Is that correct?

Thanks.
 
I think the answer is yes...once I add my new servlet to the web.xml file do I need to stop and restart WAS?


Thanks.
 
forgive me all for asking just dumn questions..

in my class HelloServlet I have only one method doGet. Does that play into what I need the url to be to call my new servlet?


I remember reading once that you always need a 'main' method?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top