I was trying to write a simple Struts 2 program.
In the struts.xml I am getting the error
The file cannot be validated as there was a connection problem.
My struts.xml is
<?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="false" />
<action name="hello"
class="hello.HelloWorldAction"
method="execute">
<result name="success">/HelloWorld.jsp</result>
</action>
</struts>
JAR files are
commons-fileupload-1.3.1.jar
commons-io-2.2.jar
commons-logging-1.1.3.jar
commons-logging-api-1.1.jar
freemarker-2.3.19.jar
javassist-3.9.0.GA.jar
ognl-3.0.6.jar
struts2-core-2.3.16.3.jar
xwork-core-2.3.16.3.jar
You forgot the <package> element, and DTD should be 2.3:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.devMode" value="false" />
<package name="default" namespace="/" extends="struts-default">
<action name="hello"
class="hello.HelloWorldAction"
method="execute">
<result name="success">/HelloWorld.jsp</result>
</action>
</package>
</struts>
Related
I have an application which is implemented in Struts 2.3.24.1, Now I need to update it in latest version of Struts 2.5.20. I upgrade the dependency and start getting errors.
Error :
There is no Action mapped for namespace [/] and action name [welcomeLink] associated with context path [/Struts2Tiles]. - [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:195)
I tried some solutions as below in struts.xml
<constant name="struts.devMode" value="true" />
<package name="default" extends="struts-default" namespace="/">
I download the whole sample example from below URL:
https://examples.javacodegeeks.com/wp-content/uploads/2017/09/Struts2Tiles.zip
Struts.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
<constant name="struts.devMode" value="true" />
<package name="default" extends="struts-default" namespace="/">
<result-types>
<result-type name="tiles"
class="org.apache.struts2.views.tiles.TilesResult" />
</result-types>
<action name="*Link" method="{1}"
class="com.jcg.struts2.tiles.LinkAction">
<result name="welcome" type="tiles">welcome</result>
<result name="friends" type="tiles">friends</result>
<result name="office" type="tiles">office</result>
</action>
</package>
</struts>
POM.xml :
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Struts2Tiles</groupId>
<artifactId>Struts2Tiles</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<!-- Servlet API Dependency -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<!-- Struts2 Core Framework Dependency -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.5.20</version>
</dependency>
<!-- Struts2 Tiles Framework Dependency -->
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-tiles-plugin</artifactId>
<version>2.5.20</version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
</build>
</project>
Expected Results:
Need to upgrade the code in Latest Struts version.
Writing a simple HelloWorld application using Struts2.5. Getting the following error.
ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
FATAL StrutsSpringObjectFactory ********** FATAL ERROR STARTING UP STRUTS-SPRING INTEGRATION **********
Looks like the Spring listener was not configured for your web app!
Nothing will work until WebApplicationContextUtils returns a valid ApplicationContext.
You might need to add the following to web.xml:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
ERROR DefaultConversionPropertiesProcessor Conversion registration error
java.lang.NullPointerException
at com.opensymphony.xwork2.spring.SpringObjectFactory.buildBean(SpringObjectFactory.java:165)
at com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:177)
at com.opensymphony.xwork2.conversion.impl.DefaultTypeConverterCreator.createTypeConverter(DefaultTypeConverterCreator.java:40)
......
INFO: Server startup in [11,384] milliseconds
Following is struts.xml file.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
<package name="default" extends="struts-default">
<action name="reg" class="action.EmployeeController">
<result name="input">/input.jsp</result>
<result name="success">/success.jsp</result>
</action>
</package>
</struts>
How can it be resolved without configuring Spring?
i am absolute beginner to Struts2. I am tying to follow tutorials on struts web site. i followed this tutorial. i have some trouble with it. i created dynamic web project on eclipse. Then i followed the tutorial. However when i run the example i get the following error.
There is no Action mapped for namespace [/] and action name [hello] associated with context path [/Hello_World_Struts_2]. - [unknown location]
i have the following directory structure
And my struts.xml file is
<?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="basicstruts2" extends="struts-default" namespace="/">
<action name="index">
<result>/index.jsp</result>
</action>
<action name="hello" class="org.apache.struts.helloworld.action.HelloWorldAction" method="execute">
<result name="SUCCESS">/HelloWorld.jsp</result>
</action>
</package>
</struts>
thanks for your responses.
The struts.xml configuration file needs to be on the classpath (as opposed to in WEB-INF).
The linked tutorial assumes a Maven build and states the struts.xml file should go in src/main/resources, which will be included in the classpath in Maven builds. Since you're ignoring that part, you'll likely want to put it in the root of your source directory.
You have to create a classes/ folder under WEB-INF/ and put in your struts.xml file!
Right click the project. Go to properties deployment build path and add all .jar files to /WEB-INF/lib. Then you shouldn't get this error.
struts.xml should be located under directory: src/struts.xml..
And WEB-INF/web.xml you we need to configure the struts based on filter..
I got the same error and got solution looking at tomcat log when restarting : doctype were missing in struts.xml
so I added
<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">
now it works !
I solved the issue by adding default-action-ref tag, for example,
<default-action-ref name="home" />
after package tag
in struts.xml
<package name="user" namespace="/" extends="struts-default">
<default-action-ref name="upload" />
I had the same issue and I was facing it because of not mentioning the namespace correctly in struts.xml.
I added the following snippet in the web.xml :
<welcome-file>login.jsp</welcome-file>
and also making the namespace as "/" default...
Hope it answers your query..
In my case I had to rename Struts.xml ---> struts.xml
I'm trying to get my Struts2 project running with Tiles and REST Plugin but I just can't get it working.
I've looked at the documentation for both and I think i'm doing it right. here are my files:
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app metadata-complete="true" 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">
<!-- listeners -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
</listener>
<!-- context params -->
<context-param>
<param-name>org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</param-name>
<param-value>/WEB-INF/tiles-tradesman.xml</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:spring-tradesman.xml</param-value>
</context-param>
<!-- filters -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<!-- filter mappings -->
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</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>
<constant name="struts.devMode" value="true" />
<!-- RESTful plugin setup -->
<constant name="struts.mapper.class" value="rest" />
<constant name="struts.convention.action.suffix" value="Controller"/>
<constant name="struts.convention.action.mapAllMatches" value="true"/>
<constant name="struts.convention.default.parent.package" value="rest-default"/>
<constant name="struts.convention.package.locators" value="tp"/>
<package name="tradesman" namespace="/beta/tradesman" extends="default">
<result-types>
<result-type name="json" class="org.apache.struts2.json.JSONResult"/>
<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" />
</result-types>
<interceptors>
<interceptor name="json" class="org.apache.struts2.json.JSONInterceptor"/>
</interceptors>
</package>
</struts>
JobAlertsController.java
package uk.co.ratedpeople.tp;
import com.opensymphony.xwork2.ActionSupport;
import java.util.logging.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
public class JobAlertsController extends ActionSupport {
private static final Logger LOGGER = Logger.getLogger(JobAlertsController.class.getName());
#Action(results={
#Result(name = SUCCESS, location = "tradesman.page.jobalerts", type = "tiles")
})
public String index() {
LOGGER.info("executing index action...");
LOGGER.info("leaving index action...");
return SUCCESS;
}
}
When i try to run the project I get this error:
SEVERE: Exception starting filter struts2
Unable to load configuration. - [unknown location]
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:437)
at org.apache.struts2.dispatcher.FilterDispatcher.init(FilterDispatcher.java:195)
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:273)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:254)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:372)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:98)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4542)
at org.apache.catalina.core.StandardContext$2.call(StandardContext.java:5220)
at org.apache.catalina.core.StandardContext$2.call(StandardContext.java:5215)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Caused by: Unable to load configuration. - [unknown location]
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:69)
at org.apache.struts2.dispatcher.Dispatcher.init_PreloadConfiguration(Dispatcher.java:380)
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:424)
... 13 more
Caused by: The Result type [tiles] which is defined in the Result annotation on the class [class uk.co.ratedpeople.tp.JobAlertsController] or determined by the file extension or is the default result type for the PackageConfig of the action, could not be found as a result-type defined for the Struts/XWork package [uk.co.ratedpeople.tp#rest-default#] - [unknown location]
at org.apache.struts2.convention.DefaultResultMapBuilder.createResultConfig(DefaultResultMapBuilder.java:427)
at org.apache.struts2.convention.DefaultResultMapBuilder.createFromAnnotations(DefaultResultMapBuilder.java:399)
at org.apache.struts2.convention.DefaultResultMapBuilder.build(DefaultResultMapBuilder.java:200)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.createActionConfig(PackageBasedActionConfigBuilder.java:864)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildConfiguration(PackageBasedActionConfigBuilder.java:650)
at org.apache.struts2.convention.PackageBasedActionConfigBuilder.buildActionConfigs(PackageBasedActionConfigBuilder.java:335)
at org.apache.struts2.convention.ClasspathPackageProvider.loadPackages(ClasspathPackageProvider.java:53)
at com.opensymphony.xwork2.config.impl.DefaultConfiguration.reloadContainer(DefaultConfiguration.java:215)
at com.opensymphony.xwork2.config.ConfigurationManager.getConfiguration(ConfigurationManager.java:66)
... 15 more
27-Jul-2011 17:07:07 org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
I'm sure i'm doing something really stupid but I can't see it myself. Anyone?
First, I would suggest putting your struts actions in a package simply called struts, I've had much less configuration issues when using standard conventions plugin architecture. Move your actions to a package like:
uk.co.ratedpeople.struts
instead of
uk.co.ratedpeople.tp;
The less out of the box configuration, the better off you typically are.
This also eliminates the need for this:
<constant name="struts.convention.package.locators" value="tp"/>
Second, part of your problem is with your xml configuration:
<struts>
<constant name="struts.devMode" value="true" />
<!-- RESTful plugin setup -->
<constant name="struts.mapper.class" value="rest" />
<constant name="struts.convention.action.suffix" value="Controller"/>
<constant name="struts.convention.action.mapAllMatches" value="true"/>
<constant name="struts.convention.default.parent.package" value="rest-default"/>
<constant name="struts.convention.package.locators" value="tp"/>
<package name="tradesman" namespace="/beta/tradesman" extends="default">
<result-types>
<result-type name="json" class="org.apache.struts2.json.JSONResult"/>
<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" />
</result-types>
<interceptors>
<interceptor name="json" class="org.apache.struts2.json.JSONInterceptor"/>
</interceptors>
</package>
Try something like this instead (providing you moved your actions as previously suggested):
<struts>
<constant name="struts.devMode" value="true" />
<!-- RESTful plugin setup -->
<constant name="struts.mapper.class" value="rest" />
<constant name="struts.convention.action.suffix" value="Controller"/>
<constant name="struts.convention.action.mapAllMatches" value="true"/>
<constant name="struts.convention.default.parent.package" value="tradesman"/>
<package name="tradesman" namespace="/beta/tradesman" extends="rest-default">
<result-types>
<result-type name="json" class="org.apache.struts2.json.JSONResult"/>
<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" />
</result-types>
</package>
</struts>
Notice the constant name="struts.convention.default.parent.package" value="tradesman" which is referring to the package below it which defines your result types and extends rest-default. This should eliminate your tiles result definition errors.
I've also run into issues using the struts filter you have in your web.xml, I would change from:
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
to:
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
This is my struts config file:
The root of my project is StrutsProject.
<?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="false" />
<package name="first" namespace="/helloworld" extends="struts-default">
<action name="HelloWorld" class="com.abc.actions.HelloWorldAction">
<result name="SUCCESS">/pages/login.jsp</result>
</action>
</package>
</struts>
I am trying to access the following URL:
http://localhost:8080/StrutsProject/helloworld/HelloWorld.action
I am getting the following error:
There is no Action mapped for action name helloworld. - [unknown location]
at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:186)
at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:41)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:497)
at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:421)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
Please help,
Siddharth
Is your JSP file location is correct??
/pages/login.jsp
Or It should be
/WEB-INF/pages/login.jsp