Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > J2EE
|
J2EE General J2EE (Java 2 Enterprise Edition) discussions. Questions not specific to EE will be redirected elsewhere.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the J2EE section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 10th, 2004, 03:31 AM
Registered User
 
Join Date: Apr 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to compile a servlet?

Hi,

There is a piece of servlet like this:

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

public class SimpleServlet extends Httpservlet{
  public void init() throws ServletException{ }
  public void doGet(HttpservletRequest req,HttpServletResponse resp)
                                 throws ServletException,IOException{
    PrintWriter out=resp.getWriter();
    resp.setContentType("text/html");

    out.println("<html>");
    //...
    out.println("</html>");
    out.flush();
  }
  public void doPost(HttpServletRequest req,HttpServletResponse resp)
                                throws ServletException,IOException{
    doGet(req,resp);
  }
  public void destroy(){ }
}

But when I compile it in command line:
< javac SimpleServlet.java >
it shows:
SimpleServlet.java:3: package javax.servlet does not exist
import javax.servlet.*;
^
SimpleServlet.java:4: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
SimpleServlet.java:7: cannot resolve symbol
symbol : class Httpservlet
symbol : class ServletException
symbol : class HttpservletRequest
...

It seems that the package 'javax.servlet' and its classes do not exist in J2sdk,J2ee.
Where is the package? How can I compile the sevlet?
My System is Windows XP and the platform is j2EE1.4 Whith j2sdk1.4.2.

By the way,my 'javac' works well when compile other j2se program using 'javax'package.

thanks,

wujie



 
Old May 13th, 2004, 12:12 PM
Registered User
 
Join Date: May 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

You are invoking a java compiler from j2sdk and are missing jars from j2ee. Solution: javac -classpath <J2EEROOT>/lib/j2ee.jar; code.java

Change <J2EEROOT> to the full path where you installed it.
There are some spelling errors too. Change Httpservlet to HttpServlet.

Cheer.





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to compile a servlet program????? sushant2002 J2EE 4 December 24th, 2007 06:42 AM
how to compile servlet? Monali Servlets 4 December 26th, 2006 04:44 PM
how to compile servlet..... Random Servlets 1 January 16th, 2006 12:28 AM
Compile Louisa VB.NET 2002/2003 Basics 1 November 23rd, 2005 10:14 AM
C# compile biran Visual Studio 2005 1 July 15th, 2005 01:36 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.