This question already has an answer here:
Struts 2 (version 2.3.28) only accepts registered locales
(1 answer)
Closed 6 years ago.
I have a multilingual struts application and recently I upgraded the struts from 2.3.20 to 2.3.29. After upgrading, the Tamil language is not working i.e. even though if we select Tamil language, the texts are shown in English.
I checked the locale setting when we select Tamil language, it is correct i.e. request_locale=ta_IN .
I tried extending I18nInterceptor in my custom interceptor class and then override the getLocaleFromParam() method as below. This also didn't work.
So please let me know if any of you has a solution for this problem.
Tamil language was working fine in Struts 2.3.20
protected Locale getLocaleFromParam(Object requestedLocale)
{
Locale locale = null;
if (requestedLocale != null) {
locale = (requestedLocale instanceof Locale) ?
(Locale) requestedLocale :
LocalizedTextUtil.localeFromString
(requestedLocale.toString(), null);
if (locale != null) {
logger.debug("applied request locale="+locale);
}
}
return locale;
}
You need to change replace your interceptor.
The default stack is defined in struts as below (https://struts.apache.org/docs/struts-defaultxml.html):
<interceptor-stack name="defaultStack">
<interceptor-ref name="exception"/>
<interceptor-ref name="alias"/>
<interceptor-ref name="servletConfig"/>
<interceptor-ref name="i18n"/>
<interceptor-ref name="prepare"/>
<interceptor-ref name="chain"/>
<interceptor-ref name="scopedModelDriven"/>
<interceptor-ref name="modelDriven"/>
<interceptor-ref name="fileUpload"/>
<interceptor-ref name="checkbox"/>
<interceptor-ref name="datetime"/>
<interceptor-ref name="multiselect"/>
<interceptor-ref name="staticParams"/>
<interceptor-ref name="actionMappingParams"/>
<interceptor-ref name="params"/>
<interceptor-ref name="conversionError"/>
<interceptor-ref name="validation">
<param name="excludeMethods">input,back,cancel,browse</param>
</interceptor-ref>
<interceptor-ref name="workflow">
<param name="excludeMethods">input,back,cancel,browse</param>
</interceptor-ref>
<interceptor-ref name="debugging"/>
You need to define your own interceptor and add it to default stack
<interceptor name="customi18n"
class="foo.bar.CustomI18NInterceptor" />
And add it to your own stack:
//Give a new name to your stack
<interceptor-stack name="customDefaultStack">
<interceptor-ref name="exception"/>
<interceptor-ref name="alias"/>
<interceptor-ref name="servletConfig"/>
//Replace your customi18n interceptor
<interceptor-ref name="customi18n"/>
//Same as above
.....
Make this stack your default
<default-interceptor-ref name="customDefaultStack"/>
Related
I am having issue with struts 2 file upload for excel file in Internet explorer. It works fine in Chrome and firefox, but I am not sure what I am missing for IE.
Here is the struts config I have:
<action name="uploadAction" method="submitServiceProfile" class="serviceProfileAction">
<!-- <interceptor-ref name="exception"/>
<interceptor-ref name="i18n"/> -->
<interceptor-ref name="fileUpload">
<param name="allowedTypes">application/ms-excel,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet</param>
<!-- <param name="maximumSize">20480</param> -->
</interceptor-ref>
<interceptor-ref name="params">
<param name="excludeParams">dojo\..*,^struts\..*</param>
</interceptor-ref>
<interceptor-ref name="validation">
<param name="excludeMethods">input,back,cancel,browse</param>
</interceptor-ref>
<interceptor-ref name="store">
<param name="operationMode">STORE</param>
</interceptor-ref>
<interceptor-ref name="someStack"/>
<result name="success" type="redirectAction">managerPage</result>
<result name="error" type="redirectAction">managerPage</result>
<result name="input" type="tiles">homepage</result>
</action>
As suggested by user497087 (Thank you!), I completely removed allowedTypes, plus the interceptor-ref "fileupload". Now, the request gets to the action without a problem at any given browser.
How can I create an interceptor that will run before EVERY action in my application, without the need to specify it for every action separately?
From http://struts.apache.org/2.3.4.1/docs/how-do-we-configure-an-interceptor-to-be-used-with-every-action.html:
Create your own named stacks and declare a new default interceptor stack for a package
<package name="default" extends="struts-default" >
<interceptors>
<interceptor-stack name="myStack">
<interceptor-ref name="timer"/>
<interceptor-ref name="logger"/>
<interceptor-ref name="default-stack"/>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="myStack"/>
<action name="login" class="tutorial.Login">
<result name="input">login.jsp</result>
<result type="redirect-action">/secure/home</result>
</action>
</package>
I am having the opposite problem of the fellow in this question:
Struts 2: excluding method from validation from just the defaultStack interceptor
The above question involved all methods being excluded, my issue is that no methods are being excluded!
I'm trying to get my authenticationInterceptor to ignore the showLogin method of my LoginAction:
<interceptors>
<interceptor name="authorizationInterceptor" class="org.companyname.struts.interceptor.AuthorizationInterceptor"/>
<interceptor-stack name="appDefault">
<interceptor-ref name="authorizationInterceptor"/>
<interceptor-ref name="defaultStack">
<param name="exception.logEnabled">true</param>
<param name="exception.logLevel">ERROR</param>
</interceptor-ref>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="appDefault" />
<action name="loginInitial" class="org.companyname.struts.action.LoginAction" method="showLogin">
<interceptor-ref name="appDefault">
<param name="authorizationInterceptor.excludeMethods">showLogin</param>
</interceptor-ref>
<result name="success">/login.jsp</result>
</action>
However, each time I forward to loginInitial, the interceptor grabs it, even though my showLogin method is being excluded.
I've checked for naming issues, and have tried putting several different values in the interceptor-ref within the action, and nothing seems to work.
What's the proper way to skip the authorizationInterceptor when I forward to loginIntial?
I believe my issue is the type of interceptor I'm using, the AbstractInterceptor. So, I just use different interceptor stacks on the actions I don't want intercepted:
<interceptor-stack name="appDefaultWithAuth">
<interceptor-ref name="defaultStack">
<param name="exception.logEnabled">true</param>
<param name="exception.logLevel">ERROR</param>
</interceptor-ref>
<interceptor-ref name="authorizationInterceptor"/>
</interceptor-stack>
<interceptor-stack name="appDefaultNoAuth">
<interceptor-ref name="defaultStack">
<param name="exception.logEnabled">true</param>
<param name="exception.logLevel">ERROR</param>
</interceptor-ref>
</interceptor-stack>
<default-interceptor-ref name="appDefaultWithAuth" />
<action name="loginInitial" class="org.company.struts.action.LoginAction" method="showLogin">
<interceptor-ref name="appDefaultNoAuth"/>
<result name="success">/login.jsp</result>
</action>
Hi
We have created a customized interceptor stack called appInterceptorStack and referred it as a <default-interceptor-ref name="appInterceptorStack"/>,
appInterceptorStack -> dont have validation and workflow interceptors attached to them.
But now for a specific action class I need to use validate method so I need validation interceptor
I created a new Interceptor stack with validation and workflow interceptors and referred it from action class. But only the default interceptor stack is getting executed. The changed one is not getting called, Please find the sample code below.
<package name="default" extends="struts-default">
<interceptor-stack name=”AppStack”>
<interceptor-ref name="exception"/>
<interceptor-ref name="alias"/>
<interceptor-ref name="params"/>
<interceptor-ref name="servletConfig"/>
<interceptor-ref name="params"/>
</interceptor-stack>
<interceptor-stack name=”GuiStack”>
<interceptor-ref name="exception"/>
<interceptor-ref name="alias"/>
<interceptor-ref name="params"/>
<interceptor-ref name="servletConfig"/>
<interceptor-ref name="params"/>
<interceptor-ref name="validation" />
<interceptor-ref name="workflow" />
</interceptor-stack>
<default-interceptor-ref name="AppStack"/>
<action name="test" class="com.jranch.Test">
<interceptor-ref name="GuiStack”/>
<result name="input">login.jsp</result>
<result name="success" type="redirect-action">/secure/home</result>
</action>
</package>
Can someone please help me?
The configuration looks correct. Can you turn on debug logging for com.opensymphony.
You can then see the interceptors being called in turn. This is the quickest way of seeing what is being called.
I am trying to get a Struts2 webapp and Jetty to play well. For some reason with Struts interceptors and FilterDispatcher configured my welcome file never get picked up I always encounter a 404. I have index.jsp in my webapp but for some reason when accessing http://localhost/webapp I always encounter 404.
For now I have set default-action-ref to my index.jsp in struts.xml but this means even for really non-existent files the user would get redirected to the index page. Is there a cleaner way to ensure Jetty picks up the welcome file? The welcome file gets picked up if the struts FilterDispatcher is not used, so I reckon it has got something to do with the way struts is configured?
The web.xml is a fairly standard web.xml with nothing fancy(?!). As I said earlier, I suspect it has got something to do with the struts.xml configuration.
struts.xml:
<constant name="struts.serve.static" value="true"/>
<constant name="struts.codebehind.pathPrefix" value="/WEB-INF/pages/"/>
<constant name="struts.configuration.classpath.defaultParentPackage" value="cms-default"/>
<constant name="struts.objectFactory" value="org.apache.struts2.spring.StrutsSpringObjectFactory"/>
<constant name="struts.custom.i18n.resources" value="cms-messages,cms-version"/>
<constant name="struts.multipart.maxSize" value="31457280"/>
<package name="cms-default" extends="codebehind-default">
<interceptors>
<interceptor-stack name="cmsStack">
<interceptor-ref name="alias" />
<interceptor-ref name="params" />
<interceptor-ref name="servletConfig" />
<interceptor-ref name="prepare" />
<interceptor-ref name="i18n" />
<interceptor-ref name="chain" />
<interceptor-ref name="modelDriven" />
<interceptor-ref name="fileUpload" />
<interceptor-ref name="checkbox" />
<interceptor-ref name="staticParams" />
<interceptor-ref name="conversionError" />
<interceptor-ref name="validation">
<param name="excludeMethods">input,back,cancel</param>
</interceptor-ref>
<interceptor-ref name="workflow">
<param name="excludeMethods">input,back,cancel</param>
</interceptor-ref>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="cmsStack" />
<default-action-ref name="index"></default-action-ref>
<global-results>
<result name="redirectToUrl" type="redirect">${redirectedToURL}</result>
</global-results>
<action name="index">
<result>/index.jsp</result>
</action>
</package>
FWIW, The problems I am encountering are almost the same ones mentioned in this email thread.
Updated With more information about the setup. Yeah the name webapp was just an example :)