I'm new in struts2 and I want to add i18n in my web application. I sea in documentation such code:
<s:url id="localeEN" namespace="/" action="locale">
<s:param name="request_locale">en</s:param>
</s:url>
<s:url id="localeruRU" namespace="/" action="locale">
<s:param name="request_locale">ru_RU</s:param>
</s:url>
<s:a href="%{localeEN}">English</s:a>
<s:a href="%{localeruRU}">Russian</s:a>
and we need to add action class like this:
public class LocalizationAction extends ActionSupport {
public String execute() {
return SUCCESS;
}
}
and in struts.xml we add this:
<struts>
<constant name="struts.custom.i18n.resources" value="global"/>
<constant name="struts.devMode" value="true"/>
<package name="default" namespace="/" extends="struts-default">
<action name="locale" class="by.bulgak.newsmanager.action.LocalizationAction">
<result name="success">index.jsp</result>
</action>
</package>
</struts>
also I have property files with names global and global_ru_RU
I do everything that I read from tutorial but when I set param in my jsp page my IDE tells me that the name request_locale is unknown property..
please tell me where is my mistake.
my IDE don't sea it and thats why when I want to change language when I run my app my IDE don't call I18n methods in struts2
The Struts2 doesn't associate default i18n property with english language.
When I set default property like this: property_name_en.properties it working fine.
But I don't understand why it is so.
I see many examples and I even start them into my machine and they work fine,
but my didn't work.. May be someone know what is problem?
Related
My current project structure is as follows
WebContent
WEB-INF
View
TestPage.jsp
other JSP pages...
My assignment is to put all JSP pages inside folder WEB-INF and do all relative changes in the project.
WebContent
WEB-INF
View
TestPage.jsp
other JSP pages...
So I have to update all result tag in struts.xml
<result name="success">/View/TestPage.jsp</result>
to
<result name="success">/WEB_INF/View/TestPage.jsp</result>
After search on web I found a plugin - struts convention plugin to achieve this, But it follows its Naming convention.
Can I override Struts convention plugin configuration (that will not follow its naming convention)?I have tried too, but it is not reflecting. My struts.xml is
<struts>
<constant name="struts.devMoade" value="true" />
<constant name="struts.convention.result.path" value="/WEB-INF/View/" />
<package name="test" extends="struts-default" namespace="/">
<action name="hello1" class="testAction.Hello1Action">
<result name="success">/TestPage.jsp</result>
</action>
</package>
</struts>
When I run
localhost:8080/project-name/hello1
It displays error 404.But if I change result in struts.xml as
<result name="success">/WEB-INF/View/TestPage.jsp</result>
It works fine.
I don't wanna do changes in all result tags.How can I achieve this by doing changes at one place?
The convention plugin uses a different configuration provider and this constant only works with configuration created by convention.
<constant name="struts.convention.result.path" value="/WEB-INF/View/" />
If you want to override the convention configuration you should use annotations.
package testAction;
#ParentPackage("json-default")
#Namespace("/")
#Action(value="hello1", results=#Result(name = "success", location="TestPage.jsp"))
public class Hello1Action extends ActionSupport {
}
Before starting, I'm sorry for my bad English, because English is not my first language. However, I have a problem with Struts 2 redirecting.
One part of my Struts.xml file is like this:
<package name="login" namespace="/" extends="struts-default">
<action name="login" class="Action.loginAction">
<result name="success" type="redirectAction">
<param name="actionName">search</param>
<param name="namespace">/</param>
</result>
<result name="error">/login.jsp</result>
<result name="input">/login.jsp</result>
</action>
</package>
I have a loginAction that's responsible for logging in the user (no matter what is the content of this file). When the result of this action is success, I want to redirect to search action. Everything works fine, but my problem is, when I redirect to search action, the URL looks like this: http://localhost:8080/MyWebApplication/search.action
I want to have the .action removed from the URL, when redirecting to a particular action. What do I need to change to fix this?
Thanks for your attention.
By default struts2 framework will add .action you can override it by following configuration.
<constant name="struts.action.extension" value=""/>
For ref:
http://struts.apache.org/release/2.3.x/struts2-core/apidocs/org/apache/struts2/dispatcher/mapper/DefaultActionMapper.html
I develop an example of Struts2 with Jasper Reports and every thing work fine. In my index.jsp I have
index.jsp:
<body>
<a href="HTML.action" target="_blank" >click to generate pdf report</a>
</body>
struts.xml:
<struts>
<package name="default" extends="struts-default,jasperreports-default">
<action name="HTML" class="com.tutorialspoint.DataBeanList" method="exporte">
<result name="success">/index.jsp</result>
</action>
</package>
</struts>
but when I want to do that with Liferay 6.0.6 I got this error:
INFO [PortalImpl:3829] Current URL /web/guest/HTML.action generates exception: null
In my struts.xml I have:
<!-- Action pour générer un rapport pdf -->
<package namespace="/reporting" extends="struts-portlet-default,json-default,jasperreports-default" name="reportingview">
<action name="HTML" class="com.xxxxxx.struts2.actions.genererQPpdf" method="exporte">
<result name="success">/JSPs/reporting/resultQP.jsp</result>
</action>
</package>
so any one can help me.
Better use the struts tags to exclude errors in the code. For example url tag could be used to construct the correct link that point to the action.
<a href="<s:url namespace="/reporting" action="HTML"/>" target="_blank" >click to generate pdf report</a>
I have developed a application using struts 2.0. On the server log I am getting certain warning lines. I want to fix this warnings but I am not able to do it.
[WARN] No configuration found for the specified action: '/' in namespace: ''. Form action defaulting to 'action' attribute's literal value.
In my struts.xml file I have something like this
<struts>
<constant name="struts.devMode" value="true" />
<package name="basicstruts2" extends="struts-default" namespace="/">
<global-results>
<result name="error">/error.jsp </result>
</global-results>
<action name="Login" class="com.login.LoginAction">
<result name="input">/login.jsp</result>
<result name="success">/dashboard.jsp</result>
</action>
</package>
</struts>
In the jsp page I am calling following javascript function on click of a button
function submitloginform()
{
document.loginform.action = "Login.action";
document.loginform.submit();
}
Can anyone please help me for this.
just keep action name in struts.xml and action of form to be submitted same.
function submitloginform()
{
document.loginform.action = "Login";
document.loginform.submit();
}
This warning message has nothing to do with the javascript or the form submission. It happens when the tag is rendered to the it's representation in HTML.
You must be missing the action attribute in your in your case. Make sure that your code looks like the following.
<s:form name="loginform" method="post" action="Login">
If you are trying to render a form in another namespace, for example: /public, you should be doing
<s:form name="loginform" method="post" action="Login" namespace="/public">
instead of
<s:form name="loginform" method="post" action="/public/Login">
I have designed an application using struts2, and need to remove the extensions for example
www.myweb.com/register.action
How to remove the .action so when I click on register it call www.myweb.com/register without action extension?
I use the following
Register
I've found the answer. I should change the struts configuration as following:
<struts>
<constant name="struts.action.extension" value=""/>
<package name="default" extends="struts-default">
<action name="register">
<result type="tiles">register</result>
</action>
</package>
</struts>