1

我有这个jsp页面,它调用servlet类。在这个servlet类中,它调用另一个java类。然后这个java类试图找到一个名为“profiles”的文件夹。但是当我尝试在浏览器上运行jsp页面时,它保持返回ClassNotFoundException(是由于指定了错误的目录还是缺少JAR文件引起的?)。我要问的问题是:如何获得该文件夹的正确路径?

编辑:
这是代码:
在 UserClientSearch.jsp 中:

    <form id="form" method="post" action="UserClientServlet">

在 UserClientServlet.java 中:

    String value = request.getParameter("screenName");
    request.setAttribute("screenName", value);

    UserClientFilterSpam fs = new UserClientFilterSpam();
    ArrayList<String> content= fs.filterSpam(value);

在 UserClientFilterSpam.java 中:

        try {
        lds.init("profiles");
    } catch (LangDetectException ex) {
        System.out.println("Error encountered: "+ ex);
    }

这是堆栈跟踪:

SEVERE: Servlet.service() for servlet [servlet.UserClientServlet] in context with path [/MarcusFYPJ] threw exception [Servlet execution threw an exception] with root cause
java.lang.ClassNotFoundException: com.cybozu.labs.langdetect.LangDetectException
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
    at servlet.UserClientServlet.doPost(UserClientServlet.java:47)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)
4

1 回答 1

1

com.cybozu.labs.langdetect.LangDetectException该错误是由类路径中缺少的事实引起的。

您需要确保它包含在已部署的 Web 应用程序中。如果它是第 3JAR 文件,它可以驻留在 Web 应用程序的WEB-INF/lib文件夹中。

于 2012-10-29T02:48:14.263 回答