path attribute of forward tag in struts-config.xml file - struts

<action-mappings>
<action name="loginAction" path="/loginAction"
type="com.xx.yy.actions.LoginAction" scope="request"
validate="false">
<forward name="landingPage" path="landingpage" />
<forward name="error" path="errorpage" />
</action>
<action name="admin" path="/adminAction"
type="com.xx.yy.actions.AdminHome" scope="request"
validate="true" input="/jsp/login.jsp">
<forward name="success" path="/jsp/admin/admin.jsp" />
<forward name="failure" path="/jsp/admin/admin.jsp" />
</action>
</action-mappings>
In the above code path attribute of forward tag is landingpage for action loginAction .
So in this case control takes to which page or action?In this context what is landingpage?Is it a jsp or another action?
In admin action path attribute of forward tags are jsps so its clear that control will be directed to jsp depending on logic in action class.

In that line...
<forward name="landingPage" path="landingpage" />
...the path attribute may be an Apache Tiles configuration name.

Related

How to create sub menuitem in intellij plugin

I have create a Menu item under the Main menu however I want to create a submenu item like this image
I have used this xml tag in the plugin.xml for menu. I want to create a submenuitem like the red marking on the image.
<actions>
<!-- Add your actions here -->
<group id="MyPlugin.test" text="_" description="test">
<add-to-group group-id="MainMenu" anchor="last" />
<!--<action id="Myplugin.Textboxes" class="Mypackage.TextBoxes" text="Text _Boxes" description="A menu item" />
<action id="Myplugin.Dialogs" class="Mypackage.MyShowDialog" text="Show _Dialog" description="A menu item" />-->
<action id="testAndroidPlugin.MyAction" class="com.test.bijesh.MyActionClass" text="Create String"
description="The action implemented by MyActionClass class">
<!--<add-to-group group-id="MainMenu" anchor="after" relative-to-action="WindowMenu"/>-->
<keyboard-shortcut keymap="$default" first-keystroke="ctrl alt S"/>
</action>
<action id="testAndroidPlugin.ManageResources" class="com.test.bijesh.actions.ColorActions" text="Create Color"
description="The action implemented by ColorAction class">
<!--<add-to-group group-id="MainMenu" anchor="after" relative-to-action="WindowMenu"/>-->
<keyboard-shortcut keymap="$default" first-keystroke="ctrl alt C"/>
</action>
</group>
</actions>
Here's how we do it in Ceylon IDE:
<actions>
<group text="Ceylon" icon="/icons/ceylon.png" popup="true">
<action> ...</action>
<add-to-group group-id="ToolsMenu" anchor="last"/>
</group>
</actions>
This results in Tools > Ceylon > .... I think your version does not work because text="_" generates an empty text (_ is used for keyboard shortcuts).
A nested action:
<actions>
<group id="YourCompany.All" popup="true" class="com.company.CompanyActionGroup">
<add-to-group group-id="MainMenu" anchor="before" relative-to-action="HelpMenu"/>
</group>
<group id="YourCompany.All.Foo" popup="true" class="com.company.FooActionGroup">
<add-to-group group-id="YourCompany.All" anchor="first"/>
<action
id="some.action"
text="Do Action"
description="This will do the action."
class="com.yourcompany.FooAction"
icon="/icons/foo.svg"
/>
</group>
</actions>
This gives
Menu: A > B > Do Action
(Where the text for A & B are defined in the class's referenced).

why does this code doesn't go into infinite loop?

1)
I'm looking at some code that is perhaps Struts1 and was wondering if someone can explain why I'm not getting an infinite loop, and instead, I'm being forwarded to a jsp page instead:
struts-config.xml:
<struts-config>
<global-forwards>
<forward name="a.t" path="/Search.do"/>
</global-forwards>
<action-mappings>
<action path="/Search"
type="path.SearchAction"
scope="request"
name="searchForm"
validate="true">
<forward name="orders" path="a.t"/>
<forward name="success" path="a.t"/>
<forward name="cancel" path="/Search.do"/>
</action>
</action-mappings>
...
</struts-config>
I searched for a.t and found it's also referenced in this
tiles.xml. Don't know what's the purpose of this.
<tiles-definitions>
<definition name="a.t" extends="admin.default">
<put-attribute name="content" value="/mypath/hello.jsp"/>
</definition>
</tiles-definitions>
Abridged SearchAction.java class:
public class SearchAction extends Action
(
....
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws
Exception
{
....
return mapping.findForward("success");
}
)
My Original thinking is that since it always returns "success", and according to the struts-config.xml
<forward name="success" path="a.t"/>
it would go to find a.t, which is defined in the global-foward
<struts-config>
<global-forwards>
<forward name="a.t" path="/Search.do"/>
</global-forwards>
and
path="/Search.do"
would in theory send me back to SearchAction.java
Since
<action-mappings>
<action path="/Search"
points to SearchAction.java
2)
I don't know why the original author decided to do:
<forward name="orders" path="a.t"/>
<forward name="success" path="a.t"/>
<forward name="cancel" path="/Search.do"/>
Is there a difference between
<forward name="success" path="a.t"/>
vs.
<forward name="success" path="/Search.do"/>
I'm being forwarded to a jsp page instead:
I hope you are being forwarded to hello.jsp
My Original thinking is that since it always returns "success", and
according to the struts-config.xml
<forward name="success" path="a.t"/>
it would go to find a.t, which is defined in the global-foward
<struts-config>
<global-forwards>
<forward name="a.t" path="/Search.do"/>
</global-forwards>
and path="/Search.do"
The path="a.t" will not again search for mapping with same name in <global-forwards>. Instead it searches for the suitable mapping in tiles.xml and finds the following block and redirects to hello.jsp
<tiles-definitions>
<definition name="a.t" extends="admin.default">
<put-attribute name="content" value="/mypath/hello.jsp"/>
</definition>
</tiles-definitions>
Is there a difference between
<forward name="success" path="a.t"/>
vs.
<forward name="success" path="/Search.do"/>
<forward name="success" path="a.t"/> will get mapped to tiles.xml and forward to hello.jsp
<forward name="success" path="/Search.do"/> will get mapped to SearchAction.java. Since you have only returned success, it will again go to hello.jsp, but the original author has done so, because in future he can add any other mapping also, for different cases say, failure
Action class:
return mapping.findForward("failure");
struts-config.xml:
<forward name="failure" path="failure.jsp"/>

does not change the locale with using LocaleAction

i use struts 1.3 and want to make localization.
that's what I'm doing:
in struts-config.xml:
<form-bean name="English" type="org.apache.struts.action.DynaActionForm">
<form-property name="language" type="String" initial="en" />
</form-bean>
<form-bean name="Russian" type="org.apache.struts.action.DynaActionForm">
<form-property name="language" type="String" initial="ru" />
</form-bean>
<action-mappings>
<action path="/English" name="English"
type="org.apache.struts.actions.LocaleAction">
<forward name="success" path="/index.jsp" />
</action>
<action path="/Russian" name="Russian"
type="org.apache.struts.actions.LocaleAction">
<forward name="success" path="/index.jsp" />
</action>
<controller processorClass="org.apache.struts.tiles.TilesRequestProcessor" />
on jsp.page
<html:link action="/Russian">
<bean:message key="jsp.header.russian"/>
</html:link>
<html:link action="/English">
<bean:message key="jsp.header.english"/>
</html:link>
maybe i do something wrong? any ideas?
P.S. yes, i have messages_ru.properties and messages_en.properties.
Oh, I found the reason, struts do not know of this type as a String.
<form-property name="language" type="java.lang.String" initial="en" />

mutiple button in HTML in struts framework

I have five buttons in my HTML code each doing differnt task . I have written one form bean and five different action classes since on click of submit button all five buttons do completely different business operation altoghether.
Am I doing it right . If so how to capture this scenarion in my struts.xml
Generally, I like to have 1 Action class for every action a user can take. So if they are executing different business logic, then I think you are right to have just 5 different Action classes.
1 form bean also probably makes sense, if all the buttons correspond to the same form.
As far as how to capture this in the struts.xml, I don't think you need to do anything special. Just configure the 5 actions as you would normally, and specify 5 different actions, all using the same form bean.
<!--This example is not tested, it is just to give you an idea-->
<form-beans>
<form-bean
name="form1"
type="app.Form1"/>
</form-beans>
<action-mappings>
<action
path="/Action1"
type="app.Action1"
name="form1"
input="/pages/input.jsp">
<forward
name="success"
path="/pages/success.jsp"/>
<forward
name="failure"
path="/pages/input.jsp"/>
</action>
<action
path="/Action2"
type="app.Action2"
name="form1"
input="/pages/input.jsp">
<forward
name="success"
path="/pages/success.jsp"/>
<forward
name="failure"
path="/pages/input.jsp"/>
</action>
<action
path="/Action3"
type="app.Action3"
name="form1"
input="/pages/input.jsp">
<forward
name="success"
path="/pages/success.jsp"/>
<forward
name="failure"
path="/pages/input.jsp"/>
</action>
<action
path="/Action4"
type="app.Action4"
name="form1"
input="/pages/input.jsp">
<forward
name="success"
path="/pages/success.jsp"/>
<forward
name="failure"
path="/pages/input.jsp"/>
</action>
<action
path="/Action5"
type="app.Action5"
name="form1"
input="/pages/input.jsp">
<forward
name="success"
path="/pages/success.jsp"/>
<forward
name="failure"
path="/pages/input.jsp"/>
</action>
</action-mappings>

HTTP Status 503 - Servlet action is currently unavailable

I am using spring source dm server version 2.0.0.
I developed one application in spring/struts/hibernate. When I am running my application in spring dm server with
it gives me error like:
HTTP Status 503 - Servlet action is currently unavailable
type: Status report
message: Servlet action is currently unavailable
description: The requested service (Servlet action is currently unavailable) is not currently available.
My web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<!-- Action Servlet Configuration -->
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>
org.apache.struts.action.ActionServlet
</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>3</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>3</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<!-- Spring Framework context Loader -->
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>
org.springframework.web.context.ContextLoaderServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Spring Framework context config location -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext*.xml
</param-value>
</context-param>
<!--TODO Prevent direct calls to *.jsp -->
<!-- Action Servlet Mapping -->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<!-- The Welcome File List -->
<welcome-file-list>
<welcome-file>start.jsp</welcome-file>
</welcome-file-list>
<!-- Define the basename for a resource bundle for I18N -->
<context-param>
<param-name>
javax.servlet.jsp.jstl.fmt.localizationContext
</param-name>
<param-value>
com.patni.temgt.web.ApplicationResources
</param-value>
</context-param>
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/SettleTest</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
and struts-config.xml is:
<form-beans>
<form-bean name="timeEntryForm"
type="com.patni.temgt.web.CreateTimeEntryActionForm" />
<form-bean name="expenseEntryForm"
type="com.patni.temgt.web.CreateExpenseEntryActionForm" />
<form-bean name="timeEntryReportForm"
type="com.patni.temgt.web.TimeEntryReportActionForm" />
<form-bean name="adminCostingCodeForm"
type="com.patni.temgt.web.AdminCostingCodeActionForm" />
<form-bean name="loginForm"
type="com.patni.temgt.web.LoginActionForm" />
<form-bean name="adminEnvironmentVariableForm"
type="com.patni.temgt.web.AdminEnvironmentVariableActionForm" />
<form-bean name="adminEmployeeForm"
type="com.patni.temgt.web.AdminEmployeeActionForm" />
<form-bean name="adminContactDetailForm"
type="com.patni.temgt.web.AdminContactDetailActionForm" />
<form-bean name="adminApplicationUserForm"
type="com.patni.temgt.web.AdminApplicationUserActionForm" />
<form-bean name="adminUserRoleForm"
type="com.patni.temgt.web.AdminUserRoleActionForm" />
<form-bean name="myCostingCodeForm"
type="com.patni.temgt.web.MyCostingCodeActionForm" />
</form-beans>
<global-forwards>
<forward name="login" path="/WEB-INF/jsp/login.jsp" />
</global-forwards>
<action-mappings>
<action path="/timeEntry"
type="com.patni.temgt.web.CreateTimeEntryAction"
name="timeEntryForm" scope="session" validate="false"
input="/WEB-INF/jsp/timeEntry.jsp">
<forward name="success" path="/WEB-INF/jsp/timeEntry.jsp" />
<forward name="invalid" path="/WEB-INF/jsp/timeEntry.jsp" />
</action>
<action path="/expenseEntry"
type="com.patni.temgt.web.CreateExpenseEntryAction"
name="expenseEntryForm" scope="session" validate="false"
input="/WEB-INF/jsp/expenseEntry.jsp">
<forward name="success" path="/WEB-INF/jsp/expenseEntry.jsp" />
<forward name="invalid" path="/WEB-INF/jsp/expenseEntry.jsp" />
<forward name="list" path="/WEB-INF/jsp/expenseList.jsp" />
<forward name="approvallist" path="/expenseApproval.htm?action=list" redirect="true" />
</action>
<action path="/expenseApproval"
type="com.patni.temgt.web.ExpenseApprovalAction"
name="expenseEntryForm" scope="session" validate="false"
input="/WEB-INF/jsp/expenseApprovalList.jsp">
<forward name="approvallist" path="/WEB-INF/jsp/expenseApprovalList.jsp" />
</action>
<action path="/adminCostingCode"
type="com.patni.temgt.web.AdminCostingCodeAction"
name="adminCostingCodeForm" scope="session" validate="false"
input="/WEB-INF/jsp/adminCostingCode.jsp">
<forward name="success" path="/WEB-INF/jsp/adminCostingCode.jsp" />
<forward name="invalid" path="/WEB-INF/jsp/adminCostingCode.jsp" />
</action>
<action path="/login"
type="com.patni.temgt.web.LoginAction"
name="loginForm" scope="session" validate="false"
input="/WEB-INF/jsp/login.jsp">
<forward name="mainPage" redirect="true"
path="/settleMain.htm" />
</action>
<action path="/settleMain"
type="com.patni.temgt.web.SettleMainAction">
<forward name="success" path="/WEB-INF/jsp/settleMain.jsp" />
</action>
<action path="/adminEnvironmentVariable"
type="com.patni.temgt.web.AdminEnvironmentVariableAction"
name="adminEnvironmentVariableForm" scope="session"
input="/WEB-INF/jsp/adminEnvironmentVariable.jsp">
<forward name="success"
path="/WEB-INF/jsp/adminEnvironmentVariable.jsp" />
<forward name="invalid"
path="/WEB-INF/jsp/adminEnvironmentVariable.jsp" />
</action>
<action path="/adminEmployee"
type="com.patni.temgt.web.AdminEmployeeAction"
name="adminEmployeeForm" scope="request"
input="/WEB-INF/jsp/adminEmployee.jsp">
<forward name="success" path="/WEB-INF/jsp/adminEmployee.jsp" />
<forward name="invalid" path="/WEB-INF/jsp/adminEmployee.jsp" />
</action>
<action path="/adminContactDetail"
type="com.patni.temgt.web.AdminContactDetailAction"
name="adminContactDetailForm" scope="request"
input="/WEB-INF/jsp/adminContactDetail.jsp">
<forward name="employee" path="/adminEmployee.htm" />
<forward name="company" path="/adminCompany.htm" />
<forward name="success" path="/WEB-INF/jsp/adminContactDetail.jsp" />
<forward name="invalid" path="/WEB-INF/jsp/adminContactDetail.jsp" />
</action>
<action path="/adminApplicationUser"
type="com.patni.temgt.web.AdminApplicationUserAction"
name="adminApplicationUserForm" scope="request"
input="/WEB-INF/jsp/adminApplicationUser.jsp">
<forward name="success" path="/WEB-INF/jsp/adminApplicationUser.jsp" />
<forward name="invalid" path="/WEB-INF/jsp/adminApplicationUser.jsp" />
</action>
<action path="/adminUserRole"
type="com.patni.temgt.web.AdminUserRoleAction"
name="adminUserRoleForm" scope="request"
input="/WEB-INF/jsp/adminUserRole.jsp">
<forward name="success" path="/WEB-INF/jsp/adminUserRole.jsp" />
<forward name="invalid" path="/WEB-INF/jsp/adminUserRole.jsp" />
</action>
<action path="/timeEntryReporting"
type="com.patni.temgt.web.TimeEntryReportAction"
name="timeEntryReportForm" scope="request"
input="/WEB-INF/jsp/timeEntryReporting.jsp">
<forward name="success" path="/WEB-INF/jsp/timeEntryReporting.jsp" />
<forward name="invalid" path="/WEB-INF/jsp/timeEntryReporting.jsp" />
</action>
<action path="/myCostingCodes"
type="com.patni.temgt.web.MyCostingCodeAction"
name="myCostingCodeForm" scope="request"
input="/WEB-INF/jsp/myCostingCodes.jsp" parameter="method">
<forward name="success" path="/WEB-INF/jsp/myCostingCodes.jsp" />
<forward name="invalid" path="/WEB-INF/jsp/myCostingCodes.jsp" />
</action>
</action-mappings>
<controller>
<set-property property="processorClass"
value="org.springframework.web.struts.DelegatingRequestProcessor" />
</controller>
<!-- ========== Message Resources Definitions =========================== -->
<!-- Will look for a properties file
com.patni.temgt.web.ApplicationResources.properties" -->
<message-resources
parameter="com.patni.temgt.web.ApplicationResources" />
<!-- Start the Spring Web Context plugin for Struts -->
<plug-in
className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/action-servlet.xml" />
</plug-in>
what could be the reason for this?
It means that the servlet identified by "action" (org.apache.struts.action.ActionServlet) failed to initialize, probably due to a configuration issue or a missing class on the class path.
There should be an exception printed in the console of your application server or in a log file. It probably will indicate what the problem is.