这是我的第一个 Struts 2 应用程序,我遇到了这个错误
"Application at context path `/HelloWorldStruts2` could not be started"
在 Tomcat 上部署时。
web.xml
我的应用程序:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>Struts 2</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
我的 struts 应用程序的 struts.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<package name="helloworld" extends="struts-default">
<action name="hello"
class="com.tutorialspoint.struts2.HelloWorldAction"
method="execute">
<result name="success">/HelloWorld.jsp</result>
</action>
</package>
</struts>
最佳答案
当您将 Web 应用程序部署到 tomcat 时,它会在处理 web.xml
后尝试创建在部署期间指定的应用程序上下文。如果您在 Web 应用程序中有错误,它可能不会启动并且不会创建上下文。您需要解决这些错误并重新部署您的应用程序。您可能有错误的配置,使用已弃用的 API,错误的库版本和不一致的依赖关系,以及其他服务器问题。很难告诉您发生了什么以及为什么您的应用程序没有启动。但提供完整的堆栈跟踪、项目配置可能有助于进一步解决问题。以下是您项目代码中其他问题的解决方案,该问题可能不存在或已经解决但未在您发布的代码中显示。这有助于在上下文 /HelloWorldStruts2
向 webapp 注册此上下文后在浏览器中启动 web 应用程序。
在 index.jsp
中你应该放置
<% response.sendRedirect("hello.action"); %>
关于java - 无法启动位于上下文路径/HelloWorldStruts2 的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17614741/