1

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>
Roman C
  • 49,761
  • 33
  • 66
  • 176

2 Answers2

0

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"); %>
Roman C
  • 49,761
  • 33
  • 66
  • 176
  • 1
    I don't think missing that would cause the app container to not launch the web app, though. – Dave Newton Jul 12 '13 at 14:18
  • @DaveNewton Without logs it couldn't be started, but after started couldn't run at context `/HelloWorldStruts2`. – Roman C Jul 12 '13 at 14:27
  • 1
    ... OP only states the application can't be started. – Dave Newton Jul 12 '13 at 14:55
  • @DaveNewton Ok, so let him/her respond and tell exactly what it means. – Roman C Jul 12 '13 at 15:49
  • here is the link from where i get all the code configuration and step for my first struts program. i did all the step and process as mentioned in this tutorial and still get that error [link] http://www.tutorialspoint.com/struts_2/struts_examples.htm – MD Ziya Shamshir Jul 12 '13 at 19:10
  • @MDZiyaShamshir Those tutorials are outdated, you should search for the newer ones or you could always use [these](http://struts.apache.org/release/2.3.x/docs/tutorials.html) tutorials. – Roman C Jul 13 '13 at 19:57
0

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>
Yohanes Gultom
  • 3,782
  • 2
  • 25
  • 38