<c:forEach var="product" items="${list}">
<tr>
<td align="center"><%-- <input type="hidden"
value="${product.productId}" name="id"> --%> <c:out
value="${product.productName}" /></td>
<td align="center"><c:out value="${product.productPrice}" /></td>
<td align="center"><input type="text" name="quantity<c:out value="${product.productId}" />"
value="<%=1%>" /></td>
<td align="center"><input type="checkbox" name="selectedItems"
value="<c:out value=" ${product.productId}"/>"/></td>
</tr>
</c:forEach>
getting null value for quantity for particular selected row by checkbox in servlet
The problem is in line name="quantity<c:out value="${product.productId}" />". Try changing to name='quantity<c:out value="${product.productId}" />' if your intention is to have name, e.g. like name=quantity1, name=quantity2, etc.
Or alternatively set the value of the quantity as ${product.productId}, e.g.
<td align="center"><input type="text" name="quantity" value='<c:out value="${product.productId}" />' /></td>
Update:
Try to simplify your problem before jumping into the loop.
Now are you able to process this as JSP POST form and see if you are able retrieve a value out of quantity?
<tr>
<td align="center"><input type="text" name="quantity" value="some default value before user overrides this" /></td>
</tr>
I want to jump between textfields, but these fields are generated dynamically through an iterator from struts-tags:
<s:iterator value="aList">
<td width="50px" align="center">
<s:textfield name="solField" size="2" maxlength="1" style="text-transform: uppercase; text-align:center"/>
</td>
</s:iterator>
I tried jumping with javascript but having the same field name is not working properly.
The code in the browser is (with three items in the list to iterate):
<td width="50px" align="center">
<input type="text" name="solField" size="2" maxlength="1" value="" id="correct_solField" style="text-transform: uppercase; text-align:center"/>
</td>
<td width="50px" align="center">
<input type="text" name="solField" size="2" maxlength="1" value="" id="correct_solField" style="text-transform: uppercase; text-align:center"/>
</td>
<td width="50px" align="center">
<input type="text" name="solField" size="2" maxlength="1" value="" id="correct_solField" style="text-transform: uppercase; text-align:center"/>
</td>
Any ideas?
Thanks in advance
How about this? (using jQuery)
$(document).on('keyup', 'input', function(){
if($(this).val().length >= $(this).attr('maxlength'))
{
$(this).nextAll('input:first').focus();
// OR even
// $(this).next('input').focus();
}
});
Is that what you're looking for? http://fiddle.jshell.net/C3jeY/
I currently have 4 forms that are working but not in the best way. They submit to the same page they are on and an if statement intercepts the request.getParameter.
I've looked at prototype.js jQuery, Struts and many others but can't seem to wrap my head around which one to use or which direction to go.
What I mainly want to do is to have a div populate with the data from a jsp.
So the psuedo-code would be something like
grab the form button submit action
get the data that /sessioninfo.jsp?sid=data would return
populate a div with that data.
Is that possible to do or is there a better way?
Example of one of my forms:
<form id="sesslook" method="post" action="/MonKaiWeb/index.jsp#tabs-1" name="Session Lookup">
<table style="text-align: center; width: 100%;" cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="vertical-align: top;">
<h1>User Activity Lookup By NetID</h1>
</td>
</tr>
<tr>
<td style="vertical-align: top;">
<input cols="25" type="text" rows="1" name="netid" placeholder="NetID" required/>
<button value="Search" name="Search">Search</button>
</td>
</tr>
<tr>
<td style="vertical-align: top;">
<label for="from">From</label>
<input type="text" id="from" name="from" placeholder="First Date Exclusive" required />
<label for="to">to</label>
<input type="text" id="to" name="to" placeholder="Last Date Exclusive" required />
</td>
</tr>
<tr>
<td style="vertical-align: top;">
<select id="choice" name="choice" required>
<option value="all">Please Select An Option</option>
<option value="all">Everything</option>
<option value="assnSub">Assignment Submissions</option>
<option value="samSub">Test & Quiz Submission</option>
<option value="db">Upload to DropBox</option>
</select>
</td>
</tr>
</tbody>
</table>
</form>
Below given is a very general way to populate the div with ajax response:
Try this:
$.post(url, {parameters}, function(response) { div.innerHTML = response });
I used this code to populate the div:
function doSomething() {
// get the form values
va = $('#name').val();
$.get('newjsp.jsp?ok='+va, function(data) {
$('#info').html(data);
});
}
I have below mentioned code in JSP Page. I am able to save all the values from below text boxes to DB. However, I read each text box name in my servlet (request.getParameter()) to save the fields. Is it possible to improve this code? like for example : to save all the values of one particular column in an array and save to db. If yes; please show an example that helps me. Also how to ignore if a row is empty. for example, user fills only two rows and rest rows are empty. I want to save only first two rows in DB.
<table class="cmn-table" id="t1" border="1" style="margin-left: 0.2em; margin- right:0em">
<col width="5%">
<col width="18%">
<col width="18%">
<col width="18%">
<col width="18%">
<col width="18%">
<tr>
<th>Sl.No</th>
<th>Source IP Address</th>
<th>Destination IP Address</th>
<th>Service and Port (TCP, UDP, etc.)</th>
<th>Start Date</th>
<th>Expiration Date</th>
</tr>
<tr>
<td style="align:center"> 1 </td>
<td><input type="text" name="name" id="name" size="20"> </td>
<td><input type="text" name="name1" id="name1" size="20"> </td>
<td><input type="text" name="name2" id="name2" size="20"> </td>
<td><input type="text" name="name3" id="name3" size="15"> <img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name3','MMddyyyy','dropdown',false,'12')" /></td>
<td><input type="text" name="name4" id="name4" size="15"><img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name4','MMddyyyy','dropdown',false,'12')" /> </td>
</tr>
<tr>
<td style="align:center"> <label> 2 </label> </td>
<td><input type="text" name="name5" id="name" size="20"> </td>
<td><input type="text" name="name6" id="name" size="20"> </td>
<td><input type="text" name="name7" id="name" size="20"> </td>
<td><input type="text" name="name8" id="name3" size="15"> <img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name3','MMddyyyy','dropdown',false,'12')" /></td>
<td><input type="text" name="name9" id="name4" size="15"><img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name4','MMddyyyy','dropdown',false,'12')" /> </td>
</tr>
<tr>
<td> <label> 3 </label> </td>
<td><input type="text" name="name10" id="name" size="20"> </td>
<td><input type="text" name="name11" id="name" size="20"> </td>
<td><input type="text" name="name12" id="name" size="20"> </td>
<td><input type="text" name="name13" id="name3" size="15"> <img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name3','MMddyyyy','dropdown',false,'12')" /></td>
<td><input type="text" name="name14" id="name4" size="15"><img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name4','MMddyyyy','dropdown',false,'12')" /> </td>
</tr>
<tr>
<td> <label>4 </label> </td>
<td><input type="text" name="name15" id="name" size="20"> </td>
<td><input type="text" name="name16" id="name" size="20"> </td>
<td><input type="text" name="name17" id="name" size="20"> </td>
<td><input type="text" name="name18" id="name3" size="15"> <img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name3','MMddyyyy','dropdown',false,'12')" /></td>
<td><input type="text" name="name19" id="name4" size="15"><img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name4','MMddyyyy','dropdown',false,'12')" /> </td>
</tr>
<tr>
<td> <label>5 </label> </td>
<td><input type="text" name="name20" id="name" size="20"> </td>
<td><input type="text" name="name21" id="name" size="20"> </td>
<td><input type="text" name="name22" id="name" size="20"> </td>
<td><input type="text" name="name23" id="name3" size="15"> <img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name3','MMddyyyy','dropdown',false,'12')" /></td>
<td><input type="text" name="name24" id="name4" size="15"><img src="../Image/cal.gif" id="" style="cursor: pointer;" onclick="javascript:NewCssCal('name4','MMddyyyy','dropdown',false,'12')" /> </td>
</tr>
</table>
As much as i understand, you want to get rid of calling request.getParameter on all the input fields.
Why dont you use below:
request.getParameterMap()
This gives you a map of all the parameter names and values. So, you can iterate through the map and keys in the map are parameter names and value for that key is/are the values for that parameter. Its a simple iteration over map. While iterating through the map, you can actually prepare your DB query as well based on other checks like null check.
I'm trying to connect to a URL with a form that has this values:
http://aulavirtual.uv.es/
How can I do this if every time I log value changes (time, token_id, hash) ? Please, help me !! I try with HttpUrlConnection and now with HttpClient 4.
<form name="login" method="post" action="/register/">
<input type="hidden" name="form:mode" value="edit">
<input type="hidden" name="form:id" value="login">
<input type="hidden" name="__confirmed_p" value="0">
<input type="hidden" name="__refreshing_p" value="0">
<input type="hidden" name="return_url" value="/dotlrn/index">
<input type="hidden" name="time" value="1352222384">
<input type="hidden" name="token_id" value="423">
<input type="hidden" name="hash" value="3F8865DB5E6603C296428A5A7C0D66C0256D5626">
<tr>
<td class="formulari">Nom d'usuari</td>
<td class="formulari">
<input type="text" id="username" name="username" value="" size="25" alt="Nom d'usuari"></td>
</tr>
<tr>
<TD class="formulari">Contrasenya</TD>
<TD class="formulari">
<input type="password" id="password" name="password" size="25" ALT="Contrasenya d'accés"></TD>
</tr>
<TR>
<TD COLSPAN="2" class="formulari1">
<div align="center">
<input id="login" type="submit" value=" Entreu " alt="Entrar al Aula Virtual">
<IMG BORDER="0" HEIGHT="25" WIDTH="25" SRC="/resources/key.gif" ALT="Entrar en modo seguro" TITLE="Entrar en modo seguro">
</div>
<!--
<Table COLSPAN="2" class="fonsgifs">
<div align="center" class="titol3">
<strong><U>Altres cursos acadèmics</U></SPAN></strong>
</table>
<BR><BR><BR>
<CENTER>
-->
<!--
<img align="center" src="/images/cabeceraOPEN.png" border = 0 align="center" alt="Conferencia OPEN" />
<BR><img align="center" src="/images/ConferenciaSofwareLibre.png" border = 0 align="center" alt="Conferencia Software Libre" />
<BR>7th OpenACS / .LRN Conference
<BR>Conferencia sobre Software Libre en Educación Superior
</CENTER>
-->
</TD>
</TR>
<TR>
<TD class="formulari1" COLSPAN="2" style="text-align:center">
<BR><BR><BR>
</TD>
</TR>
</FORM>
This form uses hidden parameters for security purposes. Every time http://aulavirtual.uv.es/ is displayed these hidden parameters change.
You could try changing your code to do the following:
GET the http://aulavirtual.uv.es/ page.
Parse the resulting HTML to extract the values of the time, token_id, and hash hidden parameters from the form element.
Do the POST as you do now, but pass in these three values instead of the fixed values you are using now.