获取jsp中文件夹的位置

时间:2012-10-29 02:25:10

标签: java jsp

我有这个调用servlet类的jsp页面。在这个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)

1 个答案:

答案 0 :(得分:1)

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

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