WARNING: No configuration found for the specified action: - java

I am getting following exception, please help to solve this issue.
Jul 16, 2013 11:18:40 AM org.apache.struts2.components.Form evaluateExtraParamsServletRequest
WARNING: No configuration found for the specified action: `'HelloWorld1'` in namespace: `''`. Form action defaulting to 'action' attribute's literal value.
index.jsp:
<s:form action="HelloWorld1" namespace="/" method="post" >
<s:textfield name="userName" label="User Name" />
<s:submit />
</s:form>
struts.xml:
<package name="default" namespace="/" extends="struts-default" >
<action name="HelloWorld1" class="java.vaannila.HelloWorld">
<result name="SUCCESS">/success.jsp</result>
</action>
</package>
HelloWorld .java:
public class HelloWorld extends ActionSupport{
//execute method
}

The error suggests that Struts 2 couldn't load your XML configuration. Make sure your struts.xml is inside WEB-INF/classes directory. (The rest of the configuration looks fine.)

If you are sure that the configurations are being loaded properly, try removing the namespace attribute or setting namespace="" instead of namespace="/".

This warning appears only when you use devMode. Turn it off and it should disappear, add the following to the struts.xml
<constant name="struts.devMode" value="false"/>

Related

Struts2 - returning to a specific section and/or part of a .jsp page

I am using the Struts2 framework and trying to get it to return to a specific section id on a page. Currently, it throws an error when I try to do the following:
<struts>
<constant name="struts.devMode" value="false"/>
<package name="default" namespace="/" extends="struts-default">
<action name="default">
<!--suppress Struts2ModelInspection -->
<result type="redirectAction">index.jsp</result>
</action>
<action name="sendEmail" class="com.brickhouse.action.EmailAction">
<result name="success">index.jsp#contact</result>
</action>
<action name="sendNewsletter" class="com.brickhouse.action.NewsletterAction">
<result name="success">index.jsp</result>
</action>
</package>
Of course, if I remove the hashtag and just let the "sendMail" action return to regular index.jsp as opposed to index.jsp#contact it works fine.
The section id that I am trying to return is contact.
<section id="contact">
<div class="container">
. . . .
</div>
</section>
Any thoughts?
You should not use a # sign as the dispatcher result, because dispatcher doesn't change URL the request is forwarded to. The resource with such name couldn't be found. Instead you can use it to build the URL or retuning a redirect result type to skip to the section (the last is never used). For example
<s:url var="skipToContact" value="#contact"/>
<s:a href="%{#skipToContact}">Skip to Contact</s:a>
...
<section id="contact"></section>
will skip to the section when you click on it. Make sure the section is not at the end of the document, i.e. the height from the section to the end of document is greater than a browser window height.

Struts 2 action method and struts.convention.result.path not working

I have problem with Struts2 action method and struts.convention.result.path
Here is my struts.xml
<struts>
<constant name="struts.action.extension" value="" />
<constant name="struts.action.excludePattern" value="/.*\.(html|jsp),/static/.*"/>
<constant name="struts.convention.result.path" value="/WEB-INF/pages/" />
<package name="user" namespace="/user" extends="struts-default">
<action name="login" class="loginAction" method="login">
<result name="success">login.jsp</result>
</action>
</package>
<struts>
When I run url "localhost:8080/venus/user/login". It display error "HTTP Status 404 - /venus/user/login.jsp"
If I change login() method to execute() method, it works.
Or if I change to <result name="success">/WEB-INF/pages/login.jsp</result>, it works.
Can anyone explain and teach me how use action method with result path config in xml?
Thank you very much!
You should specify the absolute path name.
<result name="success">/login.jsp</result>
When using Convention plugin, xml configuration isn't needed:
com.mycompany.actions.user -> namespaces "user"
LoginAction -> login.action
LoginAction#execute -> success -> user/login.jsp
LoginAction#login -> success -> user/login(-login|-success).jsp

struts2 web application not found

I have created a struts 2 application and deploy it in tomcat by creating a war file. There is nothing wrong with the file structure as below is how it display under tomcat after deploy.
css
META-INF
User
pages
login.jsp
customer_list.jsp
WEB-INF
classes
struts.xml
lib
web.xml
But it gives the below error when i try to access the web site,
HTTP Status 404 The requested resource (/LoginApplication/User/Login) is not available.
But i found when tomcat start it gives below exception. But the jar file that claims to say missing is in right path.
Unable to load configuration. - bean - jar:file:/C:/tomcat6/webapps/LoginApplication/WEB-INF/lib/struts2-core-2.3.1.2.jar!/struts-default.xml:54:89
at org.apache.struts2.dispatcher.Dispatcher.init(Dispatcher.java:449)
at org.apache.struts2.dispatcher.ng.InitOperations.initDispatcher(InitOperations.java:69)
at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.init(StrutsPrepareAndExecuteFilter.java:51)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:275)
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:397)
Below is the struts.xml file,
<struts>
<constant name="struts.devMode" value="true" />
<package name="user" namespace="/User" extends="struts-default">
<action name="Login">
<result>pages/login.jsp</result>
</action>
<action name="Welcome" class="loginapplication.action.UserLoginAction">
<result type="redirect" name="SUCCESS">Customers</result>
<result name="input">pages/login.jsp</result>
</action>
<action name="Customers" class="loginapplication.action.ViewCustomerAction">
<result name="SUCCESS">pages/customer_list.jsp</result>
</action>
</package>
</struts>
The error indicates you have got problems with struts.xml file. Pls post that here. Also use Maven for managing dependency. You will never have to bother about folders then.
Pls verify the libraries and versions in your lib.
commons-logging-1.1.jar
freemarker-2.3.8.jar
ognl-2.6.11.jar
struts2-core-2.0.6.jar
xwork-2.0.1.jar
The namespace for the requested action Login is User. The URL should be like the below
http://localhost:8080/MyApp/User/Login
Configure the XML
<package name="User" namespace="/User" extends="struts-default">
<action name="Login">
<result>pages/login.jsp</result>
</action>
</package>
Note that package name and namespace are same

Struts 2 ajax validation unable to find interceptor class jsonValidationWorkflowStack

I'm trying to implement ajax validation in my Struts 2 application. I have included struts2-json-plugin in the build path. Whenever I start the server in Eclipse, I get the following error:
Unable to find interceptor class referenced by ref-name
jsonValidationWorkflowStack - interceptor-ref -
file:/C:/path/struts.xml:15:60
This is what my struts.xml looks like:
<struts>
<constant name="struts.url.includeParams" value="all" />
<constant name="struts.devMode" value="true" />
<package name="default" extends="struts-default">
<action name="submitForm" class="action.FormAction" >
<interceptor-ref name="jsonValidationWorkflowStack"/>
<result>results.jsp</result>
<result name="input">index.jsp</result>
<result name="error">index.jsp</result>
</action>
</package>
</struts>
Why is this happening? I'm following the official struts2 ajax validation tutorial at.
You need to extend the "json-default" package.
The "struts-default" package doesn't know about the "jsonValidationWorkflowStack".

struts2.xml - can't include other .xml file

I am using struts2, for that my struts.xml file contains code like :
<?xml version="1.0" encoding="UTF-8" ?>
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="true" />
<include file="strutsAuthentication.xml"/>
<package name="default" extends="struts-default">
<interceptors>
<interceptor-stack name="crudStack">
<interceptor-ref name="checkbox" />
<interceptor-ref name="params" />
<interceptor-ref name="static-params" />
<interceptor-ref name="defaultStack" />
</interceptor-stack>
</interceptors>
</package>
And i have specified all the required actions inside the strutsAuthentication.xml. That code is :
<struts>
<package name="authentication" extends="default" namespace="/authentication">
<action name="saveCountry" class="saveCountryAction">
<interceptor-ref name="defaultStack" />
<result name="success">/savecountry.jsp</result>
<result name="error">/error.jsp</result>
</action>
</package>
When i am deploying my application into tomcat, it gives me warning that :
WARN (org.apache.struts2.components.Form:308) - No configuration found for the specified action: 'saveCountry' in namespace: ''. Form action defaulting to 'action' attribute's literal value.
It means struts.xml can't include strutsAuthentication.xml. Anyone have a solution ?? Thanx in advance....
Got d solution.... For above problem i was done a mistake in calling the action from jsp page. So namespace name "authentication" should be included at the time of calling the action class. Final solution is : "authentication/saveCountry.action".
I don't know what version of struts2 you're using but if you're using the 2.1.x branch you should look at the convention plugin http://cwiki.apache.org/S2PLUGINS/convention-plugin.html. You can get rid of 99% XML configuration.
As an add note. We should never use "xyz.action" in JSP pages. If we later need or decide to change the url-pattern from .action to .do or .html etc. We have to change all JSP pages. A better approach to compose links is:
Link Text

Categories