java - 无法启动位于上下文路径/HelloWorldStruts2 的应用程序

标签 java tomcat struts2 struts applicationcontext

这是我的第一个 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/

相关文章:

jsp - 如何重命名 SpagoBI 服务器?

java - PreparedStatement 池与连接池

java - encodeRedirectURL 改变了一些字符

java - 有什么方法可以在java中传递带有2个输入参数的函数吗?

java - 当 XML 文件重复时,到达我想要的标签的最佳方法是什么?

java - 通过包含文本查找并单击元素

html - struts <s :form > tag used for? 的 id 属性是什么

java - 找不到添加到我的自定义库的库

jsp - 如何仅在服务器上有更改时自动重新加载网页?

java - 带 DOJO 插件的 Struts 2.3.15 无法正常工作