gpt4 book ai didi

jsp - 到已编译的 jsp(servlet)的 url 映射不起作用

转载 作者:行者123 更新时间:2023-11-28 22:13:44 29 4
gpt4 key购买 nike

我直接在Tomcat的webapp目录下写了一个简单的web app,通过localhost url访问hello.jsp文件。我现在要做的是对上一步中编译的 servlet 类进行 url 映射。我的web.xml代码如下:

我希望能够指向以“/hi”结尾的 url 并运行已编译的 jsp。任何帮助将不胜感激。

<welcome-file-list>
<welcome-file>hello.jsp</welcome-file>
</welcome-file-list>

<servlet>
<servlet-name>hi</servlet-name>
<servlet-class>org.apache.jsp.hello_jsp</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>hi</servlet-name>
<url-pattern>/hi</url-pattern>
</servlet-mapping>

目前,当我尝试从我指定的 url-pattern 访问它时,我得到了这个堆栈跟踪:

type Exception report

message Error instantiating servlet class org.apache.jsp.hello_jsp

description The server encountered an internal error that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Error instantiating servlet class org.apache.jsp.hello_jsp
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1822)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
java.lang.Thread.run(Thread.java:722)
root cause

java.lang.ClassNotFoundException: org.apache.jsp.hello_jsp
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1822)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
java.lang.Thread.run(Thread.java:722)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.35 logs.

最佳答案

这确实不对。您需要使用 <jsp-file>而不是 <servlet-class> .毕竟,源代码中只有一个 JSP 文件,而不是 servlet 类。

<servlet>
<servlet-name>hi</servlet-name>
<jsp-file>/hello.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>hi</servlet-name>
<url-pattern>/hi</url-pattern>
</servlet-mapping>

关于jsp - 到已编译的 jsp(servlet)的 url 映射不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15636893/

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