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>
<%@ taglib uri="/struts-tags" prefix="s" %>
name:<s:property value="name"/>
<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 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.
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.
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).
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 ;)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.