0

I am getting the following error while try to connect to my local server.

I am accessing my page as below... http://localhost:8080/MyFirstStruts/HomeScreen.action

HTTP Status 404 - There is no Action mapped for namespace [/] and action name [HomeScreen] associated with context path [/MyFirstStruts].

My Project name is MyFirstStruts.

HomeScreen.Java code

package com.cmdb.actions;

import com.opensymphony.xwork2.ActionSupport;

public class HomeScreen extends ActionSupport {

/**
 * The action method
 * @return name of view
 */
public String execute() {

    return SUCCESS;
}


} //end of class 
 // end of class

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" 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>MyFirstStruts</display-name>


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


  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
</web-app>

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>
    <package name="default" namespace="/" extends="struts-default">
        <action name="HomeScreen" class="actions.HomeScreen"
            method="execute">
            <result name="success">/Home.jsp</result>
        </action>
    </package>
</struts>
Roman C
  • 49,761
  • 33
  • 66
  • 176

2 Answers2

0

The class path of the action you mentioned in struts.xml actions.HomeScreen is not same as your class package com.cmdb.actions These must be the same.

Roman C
  • 49,761
  • 33
  • 66
  • 176
Alireza Fattahi
  • 42,517
  • 14
  • 123
  • 173
0

The struts.xml file must be under the ../WEB-INF/classes folder, which you have to create manually and move your struts.xml file to it.

Your /WEB-INF folder tree should look something like the following:

../WEB-INF
../WEB-INF/classes
../WEB-INF/classes/struts.xml
../WEB-INF/web.xml

Also, as @Alireza mentionned, you should set your class attribute in struts.xml as following class="com.cmdb.actions.HomeScreen"

This will get you up and running.

AMIL.Y
  • 46
  • 4