Results 1 to 8 of 8
  1. #1
    aruna.hcu is offline Member
    Join Date
    Dec 2009
    Posts
    24
    Rep Power
    0

    Default How to use <s:param> tag

    I need to pass a parameter from JSP to Action class in a struts 2 project.

    In the JSP , I have
    Java Code:
    id=1;
    img src="<s:url action="imgAction"><s:param name="id" value="%{id}" /></s:url>
    The ImageAction class has getId and setId method. The id value is set when I pass the integer directly in JSP, i.e.
    Java Code:
    img src="<s:url action="imgAction"><s:param name="id" value="1" /></s:url>
    but when I provide
    Java Code:
    value=%{id}
    , it is not set, what is the correct syntax to provide in the VALUE?

    I cannot provide integer directly as it changes depending on the query.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,172
    Rep Power
    20

    Default

    Is "id" actually set somewhere for the JSP to use it?

  3. #3
    aruna.hcu is offline Member
    Join Date
    Dec 2009
    Posts
    24
    Rep Power
    0

    Default

    I get id's from an sql query. I am retrieving them in a list and need to pass them one by one to the action class. How to set them so that I can pass them as params to the Action class?

  4. #4
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    8

    Default

    Put them into a List in requestScope then loop through them using el (e.g c:foreach) while creating the img tags in the loop.

  5. #5
    aruna.hcu is offline Member
    Join Date
    Dec 2009
    Posts
    24
    Rep Power
    0

    Default

    I am unable to pass imageId value from JSP to Action class.

    This is the scenario..
    I am retrieving images from Action class onto jsp using
    Java Code:
    img src="<s:url action="imgAction">></img>
    I have to pass imageid, which should be used in the Action class to return a particular book. I am able to retrieve images but not able to pass this value to Action class. How can I achieve this?I do not have any forms in my JSP.

    I am able to setID in Action class, if I pass an integer directly
    ex:
    Java Code:
    <s:param name="id" value="89">
    but in JSP, I have
    Java Code:
    rst=stmt.executeQuery("select bookid from books_tb where category='Social and Economic' order by publish_date desc");
    These ids i kept them in a list and need to pass them one by one to the Action class and retrieve the corresponding images.

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,172
    Rep Power
    20

    Default

    For starters, you shouldn't have db code (or any code) in your JSP. It's for display, not business logic.

    That aside, r035198x has told you what you do. You should simply iterate over that List you've got using the relevant tag, then pass the integer to the value parameter.

  7. #7
    jogep is offline Member
    Join Date
    Dec 2009
    Location
    Germany
    Posts
    43
    Rep Power
    0

    Default

    Quote Originally Posted by aruna.hcu View Post
    Java Code:
    img src="<s:url action="imgAction"><s:param name="id" value="%{id}" /></s:url>
    Did it run when you use the <s: property /> tag ?

    Java Code:
    img src="<s:url action="imgAction"><s:param name="id"><s:property value="id"/></s:param></s:url>

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,172
    Rep Power
    20

    Default

    I think we need to see more of the JSP page, to be honest. Otherwise we're just guessing what is going on. We need to see the query, the assignment to a List, and the loop with the img tag in it.

Similar Threads

  1. Parsing & handling of <object> and <param> tags
    By Floxxx in forum AWT / Swing
    Replies: 1
    Last Post: 12-29-2009, 04:32 PM
  2. Javadoc - cannot compile @param tags
    By jon80 in forum New To Java
    Replies: 9
    Last Post: 05-14-2009, 09:57 AM
  3. jsp:param action
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-24-2007, 11:03 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •