LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-02-2005, 11:56 AM   #1
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092
Blog Entries: 1

Rep: Reputation: 90
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.

 
Old 03-02-2005, 04:20 PM   #2
linuxzealot
Member
 
Registered: Feb 2005
Distribution: Gentoo
Posts: 57

Rep: Reputation: 15
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))
 
Old 03-03-2005, 03:39 AM   #3
machron1
Member
 
Registered: Mar 2005
Posts: 34

Rep: Reputation: 15
try putting <%@ page session="false"%> in your jsp pages and see if that helps.
 
Old 03-03-2005, 07:07 AM   #4
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092

Original Poster
Blog Entries: 1

Rep: Reputation: 90
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.

Thanks for your interest!
 
Old 03-03-2005, 12:28 PM   #5
machron1
Member
 
Registered: Mar 2005
Posts: 34

Rep: Reputation: 15
I am not understading why you "throw" a mapping.findForward() value, most of the time this value is returned normally.

I believe if you have "redirect = true" in your struts-config.xml, it will drop the current request and create a new one.
 
Old 03-03-2005, 02:07 PM   #6
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092

Original Poster
Blog Entries: 1

Rep: Reputation: 90
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.


Last edited by eantoranz; 03-03-2005 at 02:09 PM.
 
Old 03-03-2005, 07:09 PM   #7
machron1
Member
 
Registered: Mar 2005
Posts: 34

Rep: Reputation: 15
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.
 
Old 03-03-2005, 07:47 PM   #8
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092

Original Poster
Blog Entries: 1

Rep: Reputation: 90
For sure... my mistake (when I said throw).

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.

Buy!
 
Old 03-04-2005, 12:04 PM   #9
machron1
Member
 
Registered: Mar 2005
Posts: 34

Rep: Reputation: 15
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>

Last edited by machron1; 03-04-2005 at 12:05 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
struts: is it possible to get the pagecontext in the execute method of ForwardAction? eantoranz Programming 1 03-04-2005 09:19 AM
Die, lotus notes, die (sorry for ranting) slackist General 10 01-10-2005 10:42 AM
Why the RPC request return error? liyuheu Red Hat 3 10-17-2004 11:38 PM
Why the RPC request return error? liyuheu Linux - Newbie 3 08-06-2004 11:31 PM
Die Caps lock Die! tfdml37 Linux - General 1 06-26-2004 02:00 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:37 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration