不行的:
原程序是:
package com.wrox.context.chat;import javax.servlet.*;
import javax.servlet.http.*;import java.io.*;
import java.util.*;import com.wrox.context.chat.*;
import com.wrox.util.StringUtils;
public class ChatAdminServlet extends HttpServlet
{   public void init() throws ServletException
   {
      String propsFile = getInitParameter("chatprops");
      if (propsFile == null || propsFile.length() == 0)
      {
         throw new UnavailableException(this, "chatprops not set in servlet init parameters");
      }      Properties props = new Properties();      try
      {
         InputStream is = new FileInputStream(propsFile);
         props.load(is);
         is.close();
      }
      catch (Exception e)
      {
         throw new UnavailableException(this, "Can't read the chatprops file " +
               propsFile);
      }      RoomList roomList = createRooms(props);
      getServletContext().setAttribute("roomList", roomList);
   }   public void doGet(HttpServletRequest req, HttpServletResponse res) 
                  throws IOException, ServletException
   {
      res.setContentType("text/html");
      PrintWriter out = res.getWriter();
      writePage(out);
      out.close();
   }   public void doPost(HttpServletRequest req, HttpServletResponse res) 
            throws IOException, ServletException
   {
        
      boolean isListModified = false;
      RoomList roomList = 
         (RoomList) getServletContext().getAttribute("roomList");      // Update the room list
      String[] removeList = req.getParameterValues("remove");
      if (removeList != null)
      {
         roomList.removeRooms(removeList);
         isListModified = true;
      }
      
      String roomName = req.getParameter("roomname");
      String roomDescr = req.getParameter("roomdescr");
      if (roomName != null && roomName.length() > 0)
      {
         roomList.addRoom(new ChatRoom(roomName, roomDescr));
         isListModified = true;
      }      if (isListModified)
      {
         saveList(roomList);
      }      doGet(req, res);
   }   private void saveList(RoomList roomList) throws UnavailableException
   {
      String propsFile = getServletConfig().getInitParameter("chatprops");      if (propsFile == null || propsFile.length() == 0)
      {
         throw new UnavailableException(this, "chatprops not set");
      }
        
      Properties props = new Properties();
      Enumeration rooms = roomList.getRooms();
      while (rooms.hasMoreElements())
      {
         ChatRoom room = (ChatRoom) rooms.nextElement();
         String roomName = StringUtils.replaceInString(room.getName(), " ", "+");
         props.put(roomName + ".description", room.getDescription());
      }
      try
      {
         OutputStream os = new FileOutputStream(propsFile);
         props.store(os, "Generated by ChatAdminServlet");
         os.close();
      }
      catch (Exception e)
      {
         throw new UnavailableException(this, "Can't write the chatprops file " +
            propsFile);
      }
   }   private RoomList createRooms(Properties props)
   {
      RoomList roomList = new RoomList();
      Enumeration propKeys = props.keys();
      while (propKeys.hasMoreElements())
      {
         String key = (String) propKeys.nextElement();
         if (key.endsWith(".description"))
         {
            String roomDescription = props.getProperty(key);
            String roomName = key.substring(0, key.lastIndexOf("."));
            roomName = StringUtils.replaceInString(roomName, "+", " ");
            roomList.addRoom(new ChatRoom(roomName, roomDescription));
         }
      }
      return roomList;
   }   private void writePage(PrintWriter out)
   {
      out.println("<HTML>");
      out.println("<HEAD><TITLE>Chat room administration</TITLE></HEAD>");
      out.println("<BODY>");
      out.println("<H1>Chat room administration</H1>");
      out.println("<FORM METHOD=POST ACTION=chatAdmin>");
        
      // Add check boxes for removing rooms
      out.println("Check off the rooms you would like to remove:<P>");
      RoomList roomList = (RoomList) getServletContext().getAttribute("roomList");
      Enumeration rooms = roomList.getRooms();
      while (rooms.hasMoreElements())
      {
         ChatRoom room = (ChatRoom) rooms.nextElement();
         out.println("<INPUT TYPE=CHECKBOX NAME=remove VALUE='" +
                  room.getName() + "'>" + room.getName() + "<BR>");
      }
      // Add fields for adding a room
      out.println("<P>Describe the room you would like to add:<P>");
      out.println("<TABLE>");
      out.println("<TR><TD>Name:</TD><TD><INPUT NAME=roomname SIZE=50></TD></TR>");
      out.println("<TR><TD>Description:</TD>");
      out.println("<TD><TEXTAREA NAME=roomdescr COLS=50 ROWS=15>");
      out.println("</TEXTAREA></TD></TR>");
      out.println("</TABLE>");
        
      // Add submit button
      out.println("<P><INPUT TYPE=SUBMIT VALUE='Update List'>");      out.println("</FORM>");
      out.println("</BODY></HTML>");
   }
}

解决方案 »

  1.   

    Exception in thread "main" java.lang.NoClassDefFoundError: ChatAdminServlet/java不用看源程序吧
    你的报错信息是说你的这个文件没有找到·····
    哦,你该不会还没有javac吧?
      

  2.   

    运行的时候(就是用java ....)在com文件夹外面运行,java com.wrox.context.chat.ChatAdminServlet
      

  3.   

    C:\j2sdk1.4.1_01\bin>javac C:\com\wrox\context\chat\ChatAdminServlet.java
    C:\com\wrox\context\chat\ChatAdminServlet.java:3: package javax.servlet does not
     exist
    import javax.servlet.*;
    ^
    C:\com\wrox\context\chat\ChatAdminServlet.java:4: package javax.servlet.http doe
    s not exist
    import javax.servlet.http.*;
    ^
    C:\com\wrox\context\chat\ChatAdminServlet.java:10: package com.wrox.util does no
    t exist
    import com.wrox.util.StringUtils;
                         ^
    C:\com\wrox\context\chat\ChatAdminServlet.java:13: cannot resolve symbol
      

  4.   

    .................
    .............38 errors
      

  5.   

    javax.servlet的哪一些是j2ee的
    你的系统上面有没有阿?import com.wrox.util.StringUtils;
    这个可能使你看的那个书里面附带的
    你要自己找找光盘了
      

  6.   

    .................
    .............38 errors
    error多不怕,慢慢来吧
      

  7.   

    我装了j2sdk1.4.1_01、apache2.04、tomact4.1
      

  8.   

    j2ee
    j2ee
    j2ee
    j2ee
    装一个
      

  9.   

    j2sdk1.4.1_01、apache2.04、tomact4.1
    !=
    j2ee
      

  10.   

    jswdk的路径/common/lib/servlet.jartry
      

  11.   

    我的机子还装了j2sdkee-1_3_1-win的,开什么玩笑:)
      

  12.   

    你刚才说
    装jswdk-1.0.1行吗?
    的意思不是说你有这个jswdk?
      

  13.   

    jswdk的路径/common/lib/servlet.jar
    然后我跟你说把这个路径加入到环境变量中
    然后再运行你的那个程序
    试试看