You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Ditlinger, Steve" <SD...@ebuilt.com> on 2002/03/26 19:31:21 UTC

RE: Get properties from the struts-config.xml with Struts 1.1 B eta

Under Struts 1.1, you now specify the mapping as an attribute of the
<action-mappings> element in the struts-config.xml file as seen here in this
snippet from the DTD:

----------
<!-- The "action-mappings" element configures the mappings from submitted
     request paths to the corresponding Action classes that should be
     used to process these requests.  The following attributes are
     defined:

     type           Fully qualified Java class name of the ActionMapping
                    implementation class to be used.

                     WARNING:  For Struts 1.0, this value is ignored.  You
                     can set the default implementation class name with the
                     "mapping" initialization parameter to the Struts
                     controller servlet.
-->
<!ELEMENT action-mappings (action*)>
<!ATTLIST action-mappings id             ID              #IMPLIED>
<!ATTLIST action-mappings type           %ClassName;     #IMPLIED>

-------------

hth,
Steve


-----Original Message-----
From: Falkmar Bodo Hinueber [mailto:dev@automedia.de]
Sent: Tuesday, March 26, 2002 5:16 AM
To: struts-user@jakarta.apache.org
Subject: Get properties from the struts-config.xml with Struts 1.1 Beta


Hi,
I've a problem with Struts 1.1 Beta, to read properties, which are set 
in the struts-config.xml
This code works with an old version from Struts but not with Struts 1.1 
Beta.
Can anybody help me?

Here are the sources:

The web.xml :

...
 <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>

    <init-param>
      <param-name>mapping</param-name>
      <param-value>test.myMapping</param-value>
    </init-param>
...
</servlet>
...


The struts-config.xml:


...
   
    <action    path="/test"
               name="testForm"
               type="testAction"
               scope="request"
               validate="false"
               input="/index.jsp">
           <set-property property="myProperty" value="This is property 
:)" />           
           <forward name="success"              path="/start.do"/>   
        
           <forward name="failure"              path="/index.jsp"/>   
        
    </action>
...



The myMapping.java:

package test.myMapping;
import org.apache.struts.action.ActionMapping;

public class myMapping extends ActionMapping {
    
    protected String myProperty;

    public void setMyProperty(String myProperty) {
        this.myProperty = myProperty;
    }

    public String getMyProperty() {
        return myProperty;
    }
}


The testAction.java:


public final class testAction extends Action {

   public ActionForward execute(ActionMapping mapping,
                 ActionForm form,
                 HttpServletRequest request,
                 HttpServletResponse response)
    throws IOException, ServletException {
    String myProperty=null;
    

    if (mapping instanceof myMapping)   // this doesn't work with struts 
1.1   what is the cause ?
    {
        //cast the mapping class into our custom
        //mapping class
        myMapping mp = (myMapping) mapping;

        myProperty=mp.getMyProperty();
        
    }    
    
...    


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>