0

This is the error i am getting on my eclipse server page:

There is no Action mapped for namespace [/] and action name [trial] associated with context path [/StrutsTrial6].

This is my web.xml file

<?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_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>StrutsTrial6</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.filter.StrutsPrepareAndExecuteFilter</filter-class>
  </filter>
  <filter-mapping>
  <filter-name>struts2</filter-name>
  <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>

This is my struts.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<struts>
<package name="default" extends="struts-default">
<action name="trial" namespace="/" class="first.FirstBean">
<result name="success">/first.jsp</result>
</action>
</package>
</struts>

This is my input jsp page:

<%@ taglib uri="/struts-tags" prefix="s" %>
<s:form action="trial">
<s:textfield name="name" label="NAME"></s:textfield>
<s:submit value="save"></s:submit>
</s:form>

This is my output jsp page:

<%@ taglib uri="/struts-tags" prefix="s" %>
name:<s:property value="name"/>

This is pom.xml file:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>StrutsTrial6</groupId>
  <artifactId>StrutsTrial6</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  <dependencies>
    <dependency>
      <groupId>commons-fileupload</groupId>
      <artifactId>commons-fileupload</artifactId>
      <version>1.3.2</version>
    </dependency>
    <dependency>
      <groupId>commons-io</groupId>
      <artifactId>commons-io</artifactId>
      <version>2.4</version>
    </dependency>
    <dependency>
      <groupId>commons-lang</groupId>
      <artifactId>commons-lang</artifactId>
      <version>2.4</version>
    </dependency>
    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-lang3</artifactId>
      <version>3.4</version>
    </dependency>
    <dependency>
      <groupId>commons-logging</groupId>
      <artifactId>commons-logging</artifactId>
      <version>1.1.3</version>
    </dependency>
    <dependency>
      <groupId>org.freemarker</groupId>
      <artifactId>freemarker</artifactId>
      <version>2.3.23</version>
    </dependency>
    <dependency>
      <groupId>org.javassist</groupId>
      <artifactId>javassist</artifactId>
      <version>3.20.0-GA</version>
    </dependency>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-api</artifactId>
      <version>2.7</version>
    </dependency>
    <dependency>
      <groupId>ognl</groupId>
      <artifactId>ognl</artifactId>
      <version>3.1.12</version>
    </dependency>
    <dependency>
      <groupId>org.apache.struts</groupId>
      <artifactId>struts2-core</artifactId>
      <version>2.5.10.1</version>
    </dependency>
    <dependency>
      <groupId>org.apache.tomcat</groupId>
      <artifactId>tomcat-servlet-api</artifactId>
      <version>7.0.56</version>
    </dependency>
  </dependencies>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.3</version>
        <configuration>
          <warSourceDirectory>WebContent</warSourceDirectory>
          <failOnMissingWebXml>false</failOnMissingWebXml>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

I've been stuck with this error from past 10 hours. I've also found that sometimes, when I am changing some code in my project, Eclipse server does not update my project and instead it runs my earlier code, so please tell me why my eclipse is showing such a srange behaviour.Thanks in advance..

This is the Screenshot of Config Browser page:

enter image description here

This is the same page i am getting whether i am using namespace="/" in package or not using namespace , and in this page their is no action defined in Actions in Default column.

Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
yogesh meghnani
  • 729
  • 2
  • 6
  • 11
  • 1) Enable struts2-confifgbrowser-plugin from Maven (and remember to remove it before going to production), and check on the appropriate URL where the action is published; 2) `when I am changing some code in my project, Eclipse server does not update my project and instead it runs my earlier code, so please tell me why my eclipse is showing such a srange behaviour` it is called caching :) – Andrea Ligios May 08 '17 at 14:04
  • Thanks andrea for your help....but can you please describe your first answer,as i am new in struts so i did not know much about them. – yogesh meghnani May 08 '17 at 18:55

1 Answers1

1

To debug this kind of problems:

Add this

<dependency>
    <groupId>org.apache.struts</groupId>
    <artifactId>struts2-config-browser-plugin</artifactId>
    <version>2.5.10.1</version>
</dependency>

to your pom.xml, deploy, then open the following URL:

http://localhost:8080/YOUR_PROJECT_NAME/config-browser/index.action

and discover how your actions are mapped as described here.

IMPORTANT: remember to remove it before going to production, or it will be a serious security flaw.


Your specific problem(s):

  1. Syntax errors on struts.xml:

    <package name="default" extends="struts-default">
        <action name="trial" namespace="/" class="first.FirstBean">
            <result name="success">/first.jsp</result>
        </action>
    </package>
    

    <action> has no namespace attribute, <package> does:

    <package name="default" extends="struts-default" namespace="/" >
        <action name="trial" class="first.FirstBean">
            <result name="success">/first.jsp</result>
        </action>
    </package>
    

    NOTE: don't call an Action FirstBean, since actions are not beans, actions should contain beans and expose them through getters and setters. Actions are controllers and part of the model, not just model (like a bean would be).

  2. You were not hitting the syntax errors because you're not reading the struts.xml. It is in WEB-INF, but it should stay on the root of the classpath, hence in src/main/resources, that at build time will be copied by Maven into WEB-INF/classes

Also note that WebContent/WEB-INF is not the default Maven structure generated by archetypes, which should be src/main/webapp/WEB-INF...

You would have never hit any of this errors if you'd have started from a maven archetype for the generation of your project (that instead you did manually, or with Eclipse, both discouraged ways ;)

Community
  • 1
  • 1
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
  • I had tried this,but it is not showing my action name (trial) in list – yogesh meghnani May 09 '17 at 04:57
  • Also i had changed namespace attribute in package but than also it is showing me same error. – yogesh meghnani May 09 '17 at 08:29
  • Can you edit your question adding the screenshots of the Config Browser pages ? One for the default namespace, one for the "/" namespace, etc... – Andrea Ligios May 09 '17 at 08:44
  • Thanks Andrea for your precious help...i had done what you said and i used maven archetype but than i got stuck into a new error which i had shown in my question. please check it out and provide me solution...thanks once again for your contribution.. – yogesh meghnani May 09 '17 at 19:26
  • @yogeshmeghnani, that's not how StackOverflow works. When you ask a question, and it is answered, it's over. If you have *another* question, you must ask it separately; IF the new question shares some details with the previous question, to avoid redundancy, you can simply *link* the old question from the new one. In addition to that, people like romanc is not waiting anything else to be able to close your question as a duplicate, and maybe ask for deletion, so don't feed the trolls, and just ask a new question, if there are no questions already answered that solves your problem. Cheers. – Andrea Ligios May 10 '17 at 09:11
  • I've reopened the question and rolled it back to the previous revision. If you need to retrieve what you've previously written, you can find it in the edit history, in the "edited by xxx hours" link under the question. BTW, if you'll open a new question with that body, it will be closed as duplicate :) – Andrea Ligios May 10 '17 at 09:16