Just as in Struts2 we can provide a parameter value in struts.xml as below
<action name="myS2Action" class="demo.myS2Action">
<result>/myS2Page.jsp</result>
<param name="myS2Param">value</param>
</action>
In Struts1, Is there any way to set some parameter value in struts-config.xml?
I have following entries in struts-config.xml
<form-bean name="myS1Form" type="demo.MyS1Form"></form-bean>
<action path="/myS1Action" type="demo.myS1Action" name="myS1Form" scope="request" >
<forward name="success" path="/myS1Page.jsp"></forward>
</action>
In Strut1 configuration, we can use set-property tag. Following question is related to usage of set-property tag.
In Struts1, how to use set-property tag inside action tag?
Related
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.
If a request is made to a HTML page, how to return it directly from struts.xml without going to an action?
Create an action that has a result in the struts.xml but doesn't have a class, i.e.
<package name="default" extends="struts-default">
<action name="index">
<result name="myPage">/path/to/page.html</result>
</action>
You could also create a global result, that could be found from any action, i.e
<global-results>
<result name="myPage">/path/to/page.html</result>
</global-results>
<action name="index"/>
You could create an interceptor that returns a result while intercepting and action. These are essential elements of the configuration that invoke a dispatcher to forward to requested page.
Here in a simple package I am having different URL patterns, but for only URL pattern (*.htmlx) want to call action and interceptor.
How to use wildcard in action name. I tried but it doesn't work.
<package ....... >
<action name="*.htmlx" class="net.viralpatel.struts2.action.LoginAction1">
call a interceptor
/*.........
...........
*/
</action>
<action name="*.html" class="net.viralpatel.struts2.action.LoginAction2">
/*.........
...........
*/
</action>
<action name="*.jspx" class="net.viralpatel.struts2.action.LoginAction3">
/*.........
...........
*/
</action>
</package>
You can't use action extension in action mapping as an action name, you should sort this out by defining struts action extension in the struts.xml
<constant name="struts.action.extension" value="htmlx,,"/>
My login.jsp is in the web folder.
And action for this is specified as :
struts.xml
<package name="admin" extends="struts-default" namespace="/secure">
<action class="actions.LoginAction" name="authenticateUser">
<result name="success" type="redirect">index</result>
<result name="input">/login.jsp</result>
<result name="error">/login.jsp</result>
</action>
</package>
login.jsp
<s:form action="secure/authenticateUser" method="post">
</s:form>
========================
At first request it works.
but if validate() method of action returns errors then it creates url as:
"secure/secure/authenticateUser" for the Form action attribute.
I also tried <s:url> tag but still same problem can anybody help me.
or may provide alternate solution for this.
Your action attribute on the form tag possibly has a wrong name. Use
<s:form namespace="/secure" action="authenticateUser" method="post">
i have index.jsp like this
<% response.sendRedirect("home.action"); %>
i want to invoke that action like http://localhost:8080/Myapp
but i want to remove index.jsp and i tried with
<default-action-ref name="home"/>
<action name ="home"----
but i got 404 error specifying that the action doesnot exist
What to do in this case ?
when i am putting a breakpoint in the action (class) control is not coming to action so i think that <default-action-ref name="home"/> is not working
Please provide some helpful inputs?
I don't thinks it's a good idea but it will fulfill your requirement.
<action name="">
<result type="redirectAction">home</result>
</action>
There is a Simple Logic Which I've Used
<action name="regi">
<result name="success" type="tiles">regi.tiles</result>
</action>
<action name="registration" class="com.regform">
<result name="success" type="redirect">regi.action</result>
</action>