struts: does the request die after I return from a ForwardAction?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
struts: does the request die after I return from a ForwardAction?
I have a JSP page that sets a request parameter that is not a part of a Form-Bean.
When I'm in the execute method of the ForwardAction, I'm able to see the parameter I set at a JSP page, however, when I come back to the same page (throw mapping.findForward(String)) to show the results, I can't get the request parameter values I was able to see in the ActionForward.
Is it that a new request is performed and then the values not included in the Form-Bean got "lost", so to speak?
I thought that the request that I was working with at the execute method was the same request at the JSP page.
Maybe it is because your making another request, but maybe you could store the parameter values in a variable, and have it spit out the results when you do throw mapping.findForward(String))
I don't think the session="false" trick would work.. as that will just avoid the creation of the session objetc for the client. My problem has to deal with the request.
I have done some trial-error experiments and have discovered this:
- The request object at the Action is not the same of the JSP that produces the response.
- The parameters of the action request die with it (because of the former rule). Attributes do make it to the JSP request.
So I decided to copy the parameters I told you about in my "RFC" as attributes.... it's "solved"..... well, kinda.
I checked for "redirect" in the struts-config.xml, but didn't find it.
As a matter of fact, here is my struts-config.xml file:
(spanish words in some places)
Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">
<!--
This is a blank Struts configuration file with an example
welcome action/page and other commented sample elements.
Tiles and the Struts Validator are configured using the factory defaults
and are ready-to-use.
NOTE: If you have a generator tool to create the corresponding Java classes
for you, you could include the details in the "form-bean" declarations.
Otherwise, you would only define the "form-bean" element itself, with the
corresponding "name" and "type" attributes, as shown here.
-->
<struts-config>
<!-- ============================================ Data Source Configuration -->
<!--
<data-sources>
</data-sources>
-->
<!-- ================================================ Form Bean Definitions -->
<form-beans>
<!-- el bean de login -->
<form-bean name="loginForm"
type="smile.web.struts.login.LoginForm" />
<!-- bean de busqueda de pacientes -->
<form-bean name="buscarPacientes"
type="smile.web.struts.atencionpaciente.busquedapaciente.BuscarPacienteForm" />
<!-- bean de informacion de nuevo paciente -->
<form-bean name="nuevoPaciente"
type="smile.web.struts.atencionpaciente.nuevopaciente.NuevoPacienteForm" />
</form-beans>
<!-- ========================================= Global Exception Definitions -->
<global-exceptions>
</global-exceptions>
<!-- =========================================== Global Forward Definitions -->
<global-forwards>
</global-forwards>
<!-- =========================================== Action Mapping Definitions -->
<action-mappings>
<!-- login to smile -->
<action path="/actions/login"
type="smile.web.struts.login.LoginAction"
name="loginForm"
input="/pages/login.jsp"
scope="session">
<!-- si logro entrar -->
<!-- atencion al paciente -->
<forward name="atencionpaciente" path="/pages/atencionpaciente/index.jsp" />
<forward name="success" path="/pages/principal.jsp" />
<!-- si fallo -->
<forward name="fail" path="/pages/login.jsp" />
</action><!-- login -->
<!-- logout -->
<action path="/actions/logout"
type="smile.web.struts.login.LogoutAction">
<forward name="login" path="/" />
</action>
<!-- atencion al paciente -->
<action path="/actions/atencionpaciente/buscarpaciente"
type="smile.web.struts.atencionpaciente.busquedapaciente.BuscarPacienteAction"
input="/pages/atencionpaciente/buscarpaciente.jsp"
name="buscarPacientes"
scope="request">
<forward name="hecho" path="/pages/atencionpaciente/buscarpaciente.jsp" />
</action>
<action path="/actions/atencionpaciente/nuevopaciente"
type="smile.web.struts.atencionpaciente.nuevopaciente.NuevoPacienteAction"
input="/pages/atencionpaciente/nuevopaciente.jsp"
name="nuevoPaciente"
scope="request">
<forward name="refrescar" path="/pages/atencionpaciente/nuevopaciente.jsp" />
<forward name="hecho" path="/pages/atencionpaciente/index.jsp" />
</action>
<action path="/actions/representantes/nuevorepresentante"
type="smile.web.struts.representantes.nuevorepresentante.NuevoRepresentanteAction">
<forward name="hecho" path="/pages/representantes/nuevorepresentante.jsp" />
</action>
</action-mappings>
<!-- ============================================= Controller Configuration -->
<controller
processorClass="org.apache.struts.tiles.TilesRequestProcessor"/>
<!-- ======================================== Message Resources Definitions -->
<!-- mirar en WEB-INF/classes/resources/application.properties -->
<message-resources parameter="resources.application" null="false" />
<!-- =============================================== Plug Ins Configuration -->
<!-- ======================================================= Tiles plugin -->
<!--
This plugin initialize Tiles definition factory. This later can takes some
parameters explained here after. The plugin first read parameters from
web.xml, thenoverload them with parameters defined here. All parameters
are optional.
The plugin should be declared in each struts-config file.
- definitions-config: (optional)
Specify configuration file names. There can be several comma
separated file names (default: ?? )
- moduleAware: (optional - struts1.1)
Specify if the Tiles definition factory is module aware. If true
(default), there will be one factory for each Struts module.
If false, there will be one common factory for all module. In this
later case, it is still needed to declare one plugin per module.
The factory will be initialized with parameters found in the first
initialized plugin (generally the one associated with the default
module).
true : One factory per module. (default)
false : one single shared factory for all modules
- definitions-parser-validate: (optional)
Specify if xml parser should validate the Tiles configuration file.
true : validate. DTD should be specified in file header (default)
false : no validation
Paths found in Tiles definitions are relative to the main context.
-->
<plug-in className="org.apache.struts.tiles.TilesPlugin" >
<!-- Path to XML definition file -->
<set-property property="definitions-config"
value="/WEB-INF/tiles-defs.xml" />
<!-- Set Module-awareness to true -->
<set-property property="moduleAware" value="true" />
</plug-in>
<!-- =================================================== Validator plugin -->
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property
property="pathnames"
value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>
</struts-config>
Now.. i don't understand what you don't understand. The execute method of a ForwardAction has to return an ActionForward instance. Once I know what I want to do in the execute, I call mapping.findForward(blahblah) so that struts takes me wherever I want.. that's what I understand so far (I've been programming with struts for a fairly short time.... about a month), so I could be misunderstanding a key concept here.... and I apologize if I am.
I believe your problem lies in the fact you are using TilesRequestProcessor. That is used to give individual tiles a pseudo request context like JSR168 portlets have. Unless you are actually using Tiles and Modules I would suggest you disable those plugins and use the most simple struts configuration possible. Modules are normally for large multi-developer projects and can be slightly complicated. I do like Tiles because of the clean templates, but it's really overkill for most things when you can simply use jsp:include.
If you disable Tiles and Modules and you still have a request processing problem, I don't know what else to guess.
Good Luck!
Oh and the thing I didn't understand was when you said you "throw" mapping.findForward(...) as in a throw in regard to the exception handling mechanism. I was confused about that syntax as I've never seen it used in that way.
About the plugin: Well.... let's say I'm just learning about it from what you are saying.... as a matter of fact, I don't know what you are talking about.
I just started to modify the struts-config.xml file from the one that comes with the "empty" project of the struts framework. I guess it's not "so" stripped down after all. I'll take a closer look. Thanks for worrying.
OK I have an older version of Struts 1.1 beta. I looked at my Blank application and you are right it has references to TilesRequestProcessor. The struts Example program (not Blank) would be a better reference I think. It has no reference to Tiles anywhere on it. Here is the struts-config.xml it comes with:
Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<!--
This is the Struts configuration file for the example application,
using the proposed new syntax.
NOTE: You would only flesh out the details in the "form-bean"
declarations if you had a generator tool that used them to create
the corresponding Java classes for you. Otherwise, you would
need only the "form-bean" element itself, with the corresponding
"name" and "type" attributes.
-->
<struts-config>
<!-- ========== Data Source Configuration =============================== -->
<!--
<data-sources>
<data-source>
<set-property property="autoCommit"
value="false"/>
<set-property property="description"
value="Example Data Source Configuration"/>
<set-property property="driverClass"
value="org.postgresql.Driver"/>
<set-property property="maxCount"
value="4"/>
<set-property property="minCount"
value="2"/>
<set-property property="password"
value="mypassword"/>
<set-property property="url"
value="jdbc:postgresql://localhost/mydatabase"/>
<set-property property="user"
value="myusername"/>
</data-source>
</data-sources>
-->
<!-- ========== Form Bean Definitions =================================== -->
<form-beans>
<!-- Logon form bean -->
<!--
<form-bean name="logonForm"
type="org.apache.struts.webapp.example.LogonForm"/>
-->
<!--
<form-bean name="logonForm"
type="org.apache.struts.action.DynaActionForm">
-->
<form-bean name="logonForm"
type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="username" type="java.lang.String"/>
<form-property name="password" type="java.lang.String"/>
</form-bean>
<!-- Registration form bean -->
<form-bean name="registrationForm"
type="org.apache.struts.webapp.example.RegistrationForm"/>
<!-- Subscription form bean -->
<form-bean name="subscriptionForm"
type="org.apache.struts.webapp.example.SubscriptionForm"/>
</form-beans>
<!-- ========== Global Forward Definitions ============================== -->
<global-forwards>
<forward name="logoff" path="/logoff.do"/>
<forward name="logon" path="/logon.jsp"/>
<forward name="registration" path="/registration.jsp"/>
<forward name="success" path="/mainMenu.jsp"/>
</global-forwards>
<!-- ========== Action Mapping Definitions ============================== -->
<action-mappings>
<!-- Edit user registration -->
<action path="/editRegistration"
type="org.apache.struts.webapp.example.EditRegistrationAction"
attribute="registrationForm"
scope="request"
validate="false">
<forward name="success" path="/registration.jsp"/>
</action>
<!-- Edit mail subscription -->
<action path="/editSubscription"
type="org.apache.struts.webapp.example.EditSubscriptionAction"
attribute="subscriptionForm"
scope="request"
validate="false">
<forward name="failure" path="/mainMenu.jsp"/>
<forward name="success" path="/subscription.jsp"/>
</action>
<!-- Process a user logoff -->
<action path="/logoff"
type="org.apache.struts.webapp.example.LogoffAction">
<forward name="success" path="/index.jsp"/>
</action>
<!-- Process a user logon -->
<action path="/logon"
type="org.apache.struts.webapp.example.LogonAction"
name="logonForm"
scope="session"
input="logon">
<exception
key="expired.password"
type="org.apache.struts.webapp.example.ExpiredPasswordException"
path="/changePassword.jsp"/>
</action>
<!-- Save user registration -->
<action path="/saveRegistration"
type="org.apache.struts.webapp.example.SaveRegistrationAction"
name="registrationForm"
scope="request"
input="registration"/>
<!-- Save mail subscription -->
<action path="/saveSubscription"
type="org.apache.struts.webapp.example.SaveSubscriptionAction"
name="subscriptionForm"
scope="request"
input="subscription">
<forward name="subscription" path="/subscription.jsp"/>
<forward name="success" path="/editRegistration.do?action=Edit"/>
</action>
<!-- Display the "walking tour" documentation -->
<action path="/tour"
forward="/tour.htm">
</action>
</action-mappings>
<!-- ========== Controller Configuration ================================ -->
<controller>
<!-- The "input" parameter on "action" elements is the name of a
local or global "forward" rather than a module-relative path -->
<set-property property="inputForward" value="true"/>
</controller>
<!-- ========== Message Resources Definitions =========================== -->
<message-resources
parameter="org.apache.struts.webapp.example.ApplicationResources"/>
<message-resources
parameter="org.apache.struts.webapp.example.AlternateApplicationResources"
key="alternate">
</message-resources>
<!-- ========== Plug Ins Configuration ================================== -->
<plug-in className="org.apache.struts.webapp.example.memory.MemoryDatabasePlugIn">
<set-property property="pathname" value="/WEB-INF/database.xml"/>
</plug-in>
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames"
value="/WEB-INF/validator-rules.xml,
/WEB-INF/validation.xml"/>
</plug-in>
</struts-config>
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.