1

I want to pass a single parameter with holds a username through a tag.

In the corrosponding action class I'm retreiving the parameter with request.getParameter() function, but I'm getting the value as null. here's my code

    <%
    String username="aniket";
    request.setAttribute("username",username);
    %>
 <html:link action="AllResidentInfo.do" paramName="username" paramProperty="username">All Resident's Info</html:link>

What am I doing wrong

Aniket Kibe
  • 41
  • 1
  • 2

1 Answers1

2

Straight from the documentation:

paramId

The name of the request parameter that will be dynamically added to the generated hyperlink. The corresponding value is defined by the paramName and (optional) paramProperty attributes, optionally scoped by the paramScope attribute

paramName

The name of a JSP bean that is a String containing the value for the request parameter named by paramId (if paramProperty is not specified), or a JSP bean whose property getter is called to return a String (if paramProperty is specified). The JSP bean is constrained to the bean scope specified by the paramScope property, if it is specified.

So it should be

<html:link action="AllResidentInfo.do" paramId="username" paramName="username"/>
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • Should my paramName contain the name of the jsp file which has the getter setter for "username" beacuse if i do so as you told me, its giving me the error as " No getter method for property: "username" of bean: "username" – Aniket Kibe Dec 07 '12 at 15:13
  • A JSP doesn't have getters and setters. I don't understand what you're asking. `paramId` is the name of the request parameter. `paramName` is the name of the request attribute containing the value of the parameter. So if paramId is "foo", and paramName is "bar", and you have a request attribute names "bar" which contains the string "hello", it will generate the link `AllResidentInfo.do?foo=hello`. So, the above with your scriptle code sample sould generate `AllResidentInfo.do?username=aniket` – JB Nizet Dec 07 '12 at 16:38
  • ya, i did what you told me, but it is still giving me the error, could not find bean: username in any scope.. – Aniket Kibe Dec 07 '12 at 18:04
  • I don't see how that is possible, since the line just before the link tag is `request.setAttribute("username",username);`. – JB Nizet Dec 07 '12 at 18:07