0

the following is what i do. 1. download and use all the jar 2.building web.xml in the WEB-INF

  <!--?xml version="1.0" encoding="UTF-8"?-->

<web-app id="WebApp_ID" version="3.0"
    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_3_0.xsd">

    <display-name>Basic Strust 2 Project setup on Glassfish 3.0.1</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>

</web-app>

and then setting the struts.xml in WEB-INF

    <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "/WEB-INF/classes/struts-2.1.7.dtd">

<struts>
    <!--
    You could also set the constatnts in the struts.properties file
    placed in the same directory as struts.xml
    -->
    <constant name="struts.devMode" value="true" />

    <package name="test" extends="struts-default" namespace="/">

        <!--
        If no class attribute is specified the framework will assume success and
        render the result index.jsp
        If no name value for the result node is specified the success value is the default
        -->
        <action name="help">
            <result>/help.jsp</result>
        </action>

    </package>

</struts>

and building the simple help.jsp in the root folder.

and i built the action class, help.java

import com.opensymphony.xwork2.ActionSupport;

public class help extends ActionSupport{
    @Override
    public String execute() throws Exception {
        return SUCCESS;
    }
}

actually i think for now i do not need this java code.

when i run it, and go into the help.action, it just says 404 cannot find, HTTP Status 404 - There is no Action mapped for namespace [/] and action name [help] associated with context path [/131X].

Roman C
  • 49,761
  • 33
  • 66
  • 176

1 Answers1

0

You have to specify action class which will be assigned to parse your .jsp file. In this situation help class is responsible for that, so u have to specify that as an classattribute in action tag in struts.xml.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "/WEB-INF/classes/struts-2.1.7.dtd">

<struts>
    <!--
    You could also set the constatnts in the struts.properties file
    placed in the same directory as struts.xml
    -->
    <constant name="struts.devMode" value="true" />

    <package name="test" extends="struts-default" namespace="/">

        <!--
        If no class attribute is specified the framework will assume success and
        render the result index.jsp
        If no name value for the result node is specified the success value is the default
        -->
        <action name="help" class="package_name.help">
            <result>/help.jsp</result>
        </action>

    </package>

</struts>

where package_name is a name of the package which contains help class.

Kamil Chaber
  • 568
  • 1
  • 10
  • 26
  • And what do you think will happen if class attribute is missing from action tag? – Aleksandr M Apr 29 '13 at 08:40
  • There is no action class mapped to parse .jsp file and u get HTTP Status 404. – Kamil Chaber Apr 29 '13 at 08:54
  • Nope. Please read this: http://struts.apache.org/development/2.x/docs/action-configuration.html#ActionConfiguration-ActionSupportDefault. – Aleksandr M Apr 29 '13 at 09:00
  • Didn't know about it, thx. According to problem: Maybe it is connected with path which is used to access to the help.jsp. There is importance to remember about package name and then use `...test/help.action` – Kamil Chaber Apr 29 '13 at 09:20