日期:2014-05-20  浏览次数:20869 次

菜鸟学servlet遇到问题,思考了2天还没解决
编译通过,运行错误
description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Error allocating a servlet instance
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
java.lang.Thread.run(Thread.java:619)

root cause

java.lang.NoClassDefFoundError: coreservlets9/ShowItems (wrong name: coreservlets/ShowItems)
java.lang.ClassLoader.defineClass1(Native Method)
java.lang.ClassLoader.defineClass(ClassLoader.java:620)
…………………………

源代码(书上的代码无错、路径也没问题,其他测试servlet文件都能通过 唯独这个):
package coreservlets; 

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

public class ShowItems extends HttpServlet {
  public void doGet(HttpServletRequest request,
  HttpServletResponse response)
  throws ServletException, IOException {
  HttpSession session = request.getSession();
  ArrayList previousItems =
  (ArrayList)session.getAttribute("previousItems");
  if (previousItems == null) {
  previousItems = new ArrayList();
  session.setAttribute("previousItems", previousItems);
  }
  String newItem = request.getParameter("newItem");
  response.setContentType("text/html");
  PrintWriter out = response.getWriter();
  String title = "Items Purchased";
  String docType =
  "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
  "Transitional//EN\">\n";
  out.println(docType +
  "<HTML>\n" +
  "<HEAD><TITLE>" + title + "</TITLE></HEAD>\n" +
  "<BODY BGCOLOR=\"#FDF5E6\">\n" +
  "<H1>" + title + "</H1>");
  synchronized(previousItems) {
  if ((newItem != null) &&
  (!newItem.trim().equals(""))) {
  previousItems.add(newItem);
  }
  if (previousItems.size() == 0) {
  out.println("<I>No items</I>");
  } else {
  out.println("<UL>");
  for(int i=0; i<previousItems.size(); i++) {
  out.println("<LI>" + (String)previousItems.get(i));
  }
  out.println("</UL>");
  }
  }
  out.println("</BODY></HTML>");
  }
}




--------------------------------
以下内容为自动编辑的内容,并非楼主的发贴内容,此仅用于显示而已,并无任何其他特殊作用
楼主【hppby】截止到2008-08-04 20:46:28的历史汇总数据(不包括此帖):
发帖的总数量:0 发帖的总分数:0 每贴平均分数:0  
回帖的总数量:0 得分贴总数量:0 回帖的得分率:0%