user3511659
user3511659

Reputation: 35

Regarding request.getParameter and JSTL

In one JSP I have a JSTL foreach coded like this foreach var=i begin=1 end=rowsremaining. And later in the code

   <td class=value align=left valign=top>
      <input name=${i}Last_Name value="<%=Last_Name%> type="text" />
    </td>

In the JSP that is called I have another forEach var="i" begin="1" end=rowsremaining And in the loop...

      Last_Name = (String)request.getParameter("${i}Last_Name");

Question: Why are all of my variables Last Name, First Name, Address, etc. all getting set to null? I mean I can easily guess it is because the variable i is not evaluating into the record number I was hoping it would evaluate into. The preceeding html page source for the first jsp does show the input tag names to be equal to things like 1Last_Name 16Last_Name etc. So i evaluates properly in the first jsp but not the second.

Any ideas as to why? Thanks.

Upvotes: 0

Views: 3819

Answers (3)

user3511659
user3511659

Reputation: 35

There may be more approved methods on dealing with this, but I solved my problem by (1) leaving double quotes off of the name attribute of the input tag and using the record number instead to reference each record. I.E. - Last_Name and (2) by referring to the posted arguments in the following manner Last_Name = (String)request.getParameter(Keyvalue + "Last_Name");

Upvotes: 0

JB Nizet
JB Nizet

Reputation: 691735

The JSP EL is not evaluated inside Java code.

Scriptlets contain pure Java code.

Don't use scriptlets. Use

${param[i + 'Last_Name']}

instead of

(String)request.getParameter("${i}Last_Name")

Upvotes: 2

Buhake Sindi
Buhake Sindi

Reputation: 89169

I have an issue with this line:

<input name=${i}Last_Name value="<%=Last_Name%> type="text" />

Shouldn't you quote your attribute values, like so?

<input name="${i}Last_Name" value="<%=Last_Name%>" type="text" />

Also, where is Last_Name declared and in which scope is it retrieved from?

Upvotes: 0

Related Questions