struts - pass parameters to action

Discussion in 'Java' started by Daniel Wang, Jan 16, 2005.

  1. Daniel Wang

    Daniel Wang Guest

    Hi all,

    How do I pass parameters to an action?

    For example, I want to use <html:link...> and have create a link like
    /action/MyAction.do?id=1&other=2

    How do I pass the "id" and "name" variable and their values? An example with
    <html:link> (or if not appropriate, some other tag) would be appreciated.

    Thanks in advance.
     
    Daniel Wang, Jan 16, 2005
    #1
    1. Advertising

  2. Daniel Wang

    Wendy S Guest

    "Daniel Wang" <> wrote

    > How do I pass parameters to an action?
    > For example, I want to use <html:link...> and have create a link like
    > /action/MyAction.do?id=1&other=2
    > How do I pass the "id" and "name" variable and their values? An example
    > with <html:link> (or if not appropriate, some other tag) would be
    > appreciated.


    The link tag should do it. Have you read this?
    http://struts.apache.org/userGuide/struts-html.html#link

    --
    Wendy
     
    Wendy S, Jan 16, 2005
    #2
    1. Advertising

  3. Daniel Wang

    Daniel Guest

    I know about the link tag and my tag would look like:
    <html:link
    href="/somedirectory/action/UserEdit.do?id=${user.id}">${user.lastname}</html:link>

    What I was hoping to do is use possibly use <html:link> and pass in some
    parameters without actually adding
    the "id" part to the to the href part, if you know what I mean. It seems
    more object oriented if it's passed as parameters.. Or would <html:action>
    do the trick? I just need an example somwhere.

    Thanks.


    "Wendy S" <> wrote in message
    news:61CGd.7709$nt.835@fed1read06...
    > "Daniel Wang" <> wrote
    >
    >> How do I pass parameters to an action?
    >> For example, I want to use <html:link...> and have create a link like
    >> /action/MyAction.do?id=1&other=2
    >> How do I pass the "id" and "name" variable and their values? An example
    >> with <html:link> (or if not appropriate, some other tag) would be
    >> appreciated.

    >
    > The link tag should do it. Have you read this?
    > http://struts.apache.org/userGuide/struts-html.html#link
    >
    > --
    > Wendy
    >
     
    Daniel, Jan 17, 2005
    #3
  4. Daniel Wang

    Guest

    i think you could do it this way:
    - create a form around the link. its action is UserEdit.do
    - instead of appending user.id to the query string, create a hidden
    input field that has this value. name it correctly and you don't even
    have to assign the value yourself. struts does it for you.
    - when you click on the link, instead of linking, the form submits.

    this is a little more work in your jsp file, but when you deal with
    everything in your action, accessing this data would be easier.
     
    , Jan 17, 2005
    #4
  5. Daniel Wang

    Daniel Rohe Guest

    first possible solution:

    <html:link action="/somedirectory/action/UserEdit" paramId="id"
    paramName="user" paramProperty="id">${user.lastname}</html:link>

    second possible solution:

    <html:form action="/somedirectory/action/UserEdit">
    <html:hidden name="user" property="id"/>
    <html:submit />
    </html:form>

    In the first solutions you define a link to the action "UserEdit" with a
    request parameter which name is "id" and the value is taken from the
    property "id" of the bean with the name "user".
    The second solution defines a form with a button and the same request
    parameters.

    Greetings
    Daniel

    "Daniel" <> schrieb im Newsbeitrag
    news:BhDGd.77603$Jk5.10461@lakeread01...
    >I know about the link tag and my tag would look like:
    > <html:link
    > href="/somedirectory/action/UserEdit.do?id=${user.id}">${user.lastname}</html:link>
    >
    > What I was hoping to do is use possibly use <html:link> and pass in some
    > parameters without actually adding
    > the "id" part to the to the href part, if you know what I mean. It seems
    > more object oriented if it's passed as parameters.. Or would <html:action>
    > do the trick? I just need an example somwhere.
    >
    > Thanks.
    >
    >
    > "Wendy S" <> wrote in message
    > news:61CGd.7709$nt.835@fed1read06...
    >> "Daniel Wang" <> wrote
    >>
    >>> How do I pass parameters to an action?
    >>> For example, I want to use <html:link...> and have create a link like
    >>> /action/MyAction.do?id=1&other=2
    >>> How do I pass the "id" and "name" variable and their values? An example
    >>> with <html:link> (or if not appropriate, some other tag) would be
    >>> appreciated.

    >>
    >> The link tag should do it. Have you read this?
    >> http://struts.apache.org/userGuide/struts-html.html#link
    >>
    >> --
    >> Wendy
    >>

    >
    >
     
    Daniel Rohe, Jan 17, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joe Bloggs
    Replies:
    1
    Views:
    947
    Sudsy
    Aug 3, 2003
  2. rjweytens
    Replies:
    6
    Views:
    16,298
    rjweytens
    Jun 25, 2004
  3. runescience

    Struts mapping action to action???

    runescience, Feb 6, 2006, in forum: Java
    Replies:
    3
    Views:
    1,925
    runescience
    Feb 7, 2006
  4. vyshu
    Replies:
    1
    Views:
    2,660
    Richard Senior
    Apr 27, 2007
  5. John
    Replies:
    0
    Views:
    983
Loading...

Share This Page