gpt4 book ai didi

java - 获取jsp中文件夹的位置

转载 作者:太空宇宙 更新时间:2023-11-04 07:59:08 25 4
gpt4 key购买 nike

我有一个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)

最佳答案

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

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

关于java - 获取jsp中文件夹的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13115169/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com