In my project i am trying to implement TokenSession interceptor of Struts2. I have done following entries :-
struts.xml:
<interceptor-stack name="tokenStack">
<interceptor-ref name="tokenSession"/>
<interceptor-ref name="defaultStack"/>
</interceptor-stack>
struts-module1.xml:
<action name="Action1" class="Class1" method="method1">
<interceptor-ref name="tokenStack"/>
<result name="input">one.two.three</result>
and in JSP I have added this entry:
<s:token/>
After implementing this code I am getting below exception which i tried after changing autowire properties to name instead of type but that is not a feasible solution to me.:-
2016-01-18 15:23:29 ERROR SpringObjectFactory:[main]->->-> : Error building bean
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.apache.struts2.interceptor.TokenSessionStoreInterceptor': Unsatisfied dependency expressed through bean property 'textProvider': : Error creating bean with name 'abc'
Please help me with this problem provided i want to go with autowiring as 'type' only and struts version is 2.3 (Struts.xml).
Related
I am using struts2 (struts2-core-2.3.16.3.jar) and unable to get the below configuration to work when there is a unknown action is requested.
<global-results>
<result name="globalError">/jsp/common/error.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping exception="java.lang.Exception" result="globalError"/>
</global-exception-mappings>
The browser still shows the raw message :
HTTP Status 404 - There is no Action mapped for namespace [/] and action name [signups] associated with context path [].
I am using the following workaround temporarly (it works)
<action name="*" class="com.action.UknownAction">
<result name="success">/jsp/common/error.jsp</result>
</action>
I am configuring the dynamicjasper to my struts2 but it raises an error. First of all I using the following jar files:
DynamicJasper-4.0.3
DynamicJasper-4.0.3-javadoc
DynamicJasper-4.0.3-sources
DynamicJasper-4.0.3-tests
DynamicJasper-4.0.3-test-sources
DynamicJasper-Struts2-1.3
jasperreports-4.7.0
struts2-jasperreports-plugin-2.0.11.1-sources
<result-types>
<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" />
<result-type name="redirectAction"
class="org.apache.struts2.dispatcher.ServletActionRedirectResult"/>
<result-type name="dynamic-jasper" class="ar.com.fdvs.dj.struts2.DJStruts2Result"/>
</result-types>
<action name="dynamicreport" class="ActionClass.DynamicJasperAction">
<interceptor-ref name="defaultLoginStack"/>
<param name="operation">showreport</param>
<result name="SUCCESS" type="dynamic-jasper">
<param name="format">PDF</param>
</result>
</action>
When I run the application it displays the following error in glass fish 3+ output window:
INFO: ERROR (org.apache.struts2.dispatcher.Dispatcher:38) - Dispatcher initialization failed
Unable to load configuration. - action - file:/G:/Project/IG/LIMSs/build/web/WEB-INF/classes/struts.xml:2996:78
Caused by: There is no result type defined for type 'dynamic-jasper' mapped with name 'SUCCESS'. Did you mean 'dynamicJasper'? - result - file:/G:/Project/IG/LIMSs/build/web/WEB-INF/classes/struts.xml:2999:58
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.buildResults(XmlConfigurationProvider.java:645)
at com.opensymphony.xwork2.config.providers.XmlConfigurationProvider.addAction(XmlConfigurationProvider.java:379)
... 57 more
INFO: WEB0671: Loading application [IMsys] at [/LIMSs]
INFO: IMsys was successfully deployed in 71,796 milliseconds.
WARNING: StandardWrapperValve[jsp]: PWC1406: Servlet.service() for servlet jsp threw exception
The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location]
Error in browser as follows:
exception
org.apache.jasper.JasperException: The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location]
root cause
The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location]
I'm not sure how to configure the dynamic jasper, can you advise?
just download DynamicJasper-4.0.3-test-sources.jar instead of DynamicJasper-4.0.3-test.jar then add the problem is solved.
I'm having an issue removing the #Action and #Result Convention plugin annotations from an action and replacing them with the equivalent config in struts.xml.
package com.microed.cars.web;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import com.opensymphony.xwork2.ActionSupport;
public class HomeAction extends ActionSupport {
#Action(results = {
#Result(location = "/jsp/home.jsp")
})
#Override
public String execute() throws Exception {
return super.execute();
}
}
When these annotations are there, I can successfully access localhost:port/context/home.action
When I remove the annotations I get 'no result defined for action..... ' struts error, despite there being a 'capture all' result in struts.xml - the entire struts.xml is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
"http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.devMode" value="true"/>
<constant name="struts.convention.package.locators" value="web"/>
<constant name="struts.convention.default.parent.package" value="beetroot"/>
<package name="beetroot" extends="json-default">
<action name="home" class="homeAction">
<result>/jsp/home.jsp</result>
</action>
<action name="cars" class="baseCarsAction">
<result name="input" type="json">
<param name="root">autoResults</param>
/jsp/home.jsp
</result>
</action>
</package>
</struts>
It extends json-default because I need the json result type for an autocomplete function.
I don't know why it's not picking up the action mapping for the homeAction class. I know struts.xml is being read because if I remove the action mapping "cars" then the autocomplete is disabled (but this needs the annotations which I'm trying to remove in order to validate this).
I know that 'no result defined' is a simple error, usually caused by spelling/capitalization errors but this is definitely not the case here, it's simply seems to be ignoring the whole "home" action mapping.
When stepping through DefaultActionInvocation.createResult, there are no 'results' at all for it to try to match against.
As it stands the cars action declaration isn't valid (nor does it make sense, IMO):
<action name="cars" class="baseCarsAction">
<result name="input" type="json">
<param name="root">autoResults</param>
<param name="location">/jsp/home.jsp</param>
</result>
</action>
That said: if it's a JSON result, a JSP isn't helpful, and it'll be ignored (or downright rejected, I'm not sure if it's an error or not). A single result will be either JSON, or HTML.
Turn logging up to DEBUG level to catch startup errors to narrow the range of possible causes.
If baseAction is configured in your Spring config file (which is unnecessary if you're using Spring annotations for injection) the configuration for the home action is valid.
I'd be wary of deploying the convention plugin if you're not actually using it: it changes how actions are mapped; it may have an impact on the surrounding application and cause problems. Stick with one or the other, avoid both–it makes it harder to reason about the source of application behavior.
Unrelated, but I recommend putting JSP pages under /WEB-INF to disallow direct client access.
i have done some pages with Struts 2.(J2EE project)
All was ok until i try to add an interceptor.
It seems that the Interceptor delete all properties of my Class Action and Parameters send by the jsp with url like: action?param=xxx
here is the interceptor:
public class SessionInterceptor extends AbstractInterceptor{
#Override
public String intercept(ActionInvocation invocation) throws Exception {
return invocation.invoke();
}
here is the struts.xml:
<action name="movefc_ShowFjt" class="struts2.ShowFjtAction" method="movefc">
<interceptor-ref name="sessionInterceptor"></interceptor-ref>
<result name="input" type="dispatcher">jsp/showFjt.jsp</result>
<result name="success" type="dispatcher">jsp/showFjt.jsp</result>
</action>
in the class action,
public class ShowFjtAction extends ActionSupport {
private String param;
private Personne p;
param property never receive value from the jsp (it is ok when interceptor is off). Worse, other properties in Class action seems to be erased.
Is that an normal effect of the return invocation.invoke(); of the interceptor ?
Is there anything i can do to fix that ?
y defining your own interceptor are you causing all of the default interceptors to be discarded?
Should you perhaps be defining an interceptor stack which includes your interceptor and the default stack?
<package name="default" extends="struts-default">
<interceptors>
<interceptor name="sessionInterceptor" class="SessionInterceptor"/>
<interceptor-stack name="myStack">
<interceptor-ref name="sessionInterceptor"/>
</interceptor-stack>
</interceptors>
<action name="movefc_ShowFjt"
class="struts2.ShowFjtAction">
<interceptor-ref name="myStack"/>
<result name="input" type="dispatcher">jsp/showFjt.jsp</result>
<result name="success" type="dispatcher">jsp/showFjt.jsp</result>
</action>
The entire concept is explained as follows
1] First when user does not writes any interceptors, then interceptors defined in struts-default.xml will be used. It is defined in struts-core.jar, it is accomplished by extending the "struts-default" extended in our package xml tag.
2] When user writes his own interceptor if you add one mode code block after sessionInterceptor ref name i.e interceptor-ref name="defaultStack" will solve your problem.
Befor trying this try to unzip the struts-core.jar and move forward with your implementation.
I have a default package w/ an interceptor configure, and i'm extending that package into another one and calling the same interceptor
<action name="availability**">
<param name="subTab">availability</param>
<interceptor-ref name="tabStack"/>
<result>/WEB-INF/jsp/index.jsp?include=visibilit/availability.jsp</result>
</action>
The problem is that the param is not being read inside my interceptor code:
Map params = invocation.getInvocationContext().getParameters();
subTab = params.get("subTab").toString(); //NULL exception
Any idea how i can pass parameters to extended interceptors?
Thanks!
The getParameters() method which you are calling only returns the parameters from the HTTP request. The parameters set in struts.xml with are called "static parameters", and you can access them (within the intercept() method) like this:
ActionConfig config = invocation.getProxy().getConfig();
Map<String, String> parameters = config.getParams();
String subTab = params.get("subTab");
Source: StaticParametersInterceptor.java
Can you try this syntax
<action name="availability**">
<interceptor-ref name="tabStack">
<param name="subTab">availability</param>
</interceptor-ref>
</action>
I am not sure but maybe this will work