Application at context path /HelloWorldStruts2 could not be started

吃可爱长大的小学妹 提交于 2020-01-16 05:30:07

问题


This is the my first Struts 2 application and I got this error

"Application at context path `/HelloWorldStruts2` could not be started" 

when deploying on Tomcat.

web.xml of my application:

<?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 of my struts application:

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

回答1:


When you deploy your web application to tomcat it will trying to create an application context specified during deployment after processing the web.xml. If you have errors in the web application it might not started and context is not created. You need to resolve those errors and redeploy your application. You might have wrong configuration, that use a deprecated API, wrong library versions and inconsistent dependencies, other server problems. It's difficult to tell you what happened and why your application isn't started. But providing full stacktrace, project configuration might help to further troubleshoot the problem. Below is the solution to the other problem which is in your project code, that may be not exist or already resolved but not shown in your code posted. This helps to start the web application in the browser at context /HelloWorldStruts2 after this context is registered with the webapp.

In the index.jsp you should place

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



回答2:


I think the problem is in the web.xml schema version and the filter (as mentioned by others). This one works for me :

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


来源:https://stackoverflow.com/questions/17614741/application-at-context-path-helloworldstruts2-could-not-be-started

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!