【问题标题】:Application at context path /HelloWorldStruts2 could not be started无法启动上下文路径 /HelloWorldStruts2 处的应用程序
【发布时间】:2025-12-05 18:20:06
【问题描述】:

这是我的第一个 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.xml 我的 struts 应用程序:

<?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>

【问题讨论】:

  • 服务器日志中有什么?您正在部署哪些库?
  • 您可能使用的是旧过滤器:*.com/a/17103563/1654265
  • 哦,什么版本的 S2?正如 Andrea 所提到的,这是一个已弃用的过滤器,尽管它应该仍然可以工作。
  • @AndreaLigios: 更换过滤器后仍然报同样的错误
  • @DaveNewton: struts-2.3.15

标签: java tomcat struts2 struts applicationcontext


【解决方案1】:

当您将 Web 应用程序部署到 tomcat 时,它会在处理 web.xml 后尝试创建在部署期间指定的应用程序上下文。如果您在 Web 应用程序中有错误,它可能不会启动并且不会创建上下文。您需要解决这些错误并重新部署您的应用程序。你可能有错误的配置,使用了不推荐使用的 API,错误的库版本和不一致的依赖关系,其他服务器问题。很难告诉您发生了什么以及为什么您的应用程序没有启动。但是提供完整的堆栈跟踪,项目配置可能有助于进一步解决问题。以下是您的项目代码中其他问题的解决方案,该问题可能不存在或已解决但未显示在您发布的代码中。这有助于在上下文注册到 webapp 后,在浏览器中的上下文 /HelloWorldStruts2 处启动 Web 应用程序。

您应该在index.jsp 中放置

<% response.sendRedirect("hello.action"); %>

【讨论】:

  • 不过,我不认为缺少这会导致应用容器无法启动 Web 应用。
  • @DaveNewton 没有日志就无法启动,但启动后无法在上下文/HelloWorldStruts2运行。
  • ... OP 只声明应用程序无法启动。
  • @DaveNewton 好的,让他/她回答并准确说明它的含义。
  • 这里是我的第一个 struts 程序的所有代码配置和步骤的链接。我完成了本教程中提到的所有步骤和过程,但仍然出现该错误 [link] tutorialspoint.com/struts_2/struts_examples.htm
【解决方案2】:

我认为问题出在 web.xml 架构版本和过滤器中(正如其他人所提到的)。这个对我有用:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

  <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.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  </filter>

  <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

</web-app>

【讨论】:

    最近更新 更多