Click to See Complete Forum and Search --> : Pressing the enter key at JSP page receive extra invalid data


albertkao
05-31-2010, 11:06 AM
Pressing the enter key at the jsp page receive extra invalid data at the ProdController.java.
The alertgroupStr receive "unack" as expected.
However, I do not understand why alertgroupStr receive the extra invalid "null" later.
Debug log:
11:14:52,187 DEBUG com.systems.monitoring.war.ProdController:54 - alertgroupStr unack
...
11:14:52,187 DEBUG com.systems.monitoring.war.ProdController:54 - alertgroupStr null

ProdController.java:

public ModelAndView handleRequestInternal(HttpServletRequest request,
HttpServletResponse response) throws Exception {
String alertgroupStr = request.getParameter("alertgroup");
logger.debug("alertgroupStr " + alertgroupStr);

Jsp page:
<?xml version="1.0" encoding="UTF-8" ?>
<%@ include file="/WEB-INF/jsp/includeTaglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" media="all"
href="/static/css/style.css" />
<link rel="stylesheet" type="text/css" media="all"
href="/static/css/tablist.css" />
<script type="text/javascript" src="/static/js/prototype.js"></script>
<script type="text/javascript" src="js/util.js"></script>
<title>Hw Monitoring
<%@page import="org.springframework.beans.*" %>
<%@page import="org.springframework.context.*" %>
<%@page import="org.springframework.web.servlet.support.*" %>
</title>

<style type="text/css">
.pageNumber {
float:left;
padding: 3px 0;
margin-left: 0;
margin-bottom: 0;
margin-top: 0.1em;
font: bold 12px Verdana;
}
.rowPerPage {
float:left;
padding: 3px 0;
margin-left: 0;
margin-bottom: 0;
margin-top: 0.1em;
font: bold 12px Verdana;
}
</style>
</head>
<script type="text/javascript">
function isEmpty(v) {
return (v == null) || (v.length == 0);
}

function isInteger(v) {
return !isEmpty(v) && !/[^\d]/.test(v);
}

function setalertgroup() {
var alertgroup = 'all';
var elem = document.getElementsByName("alertradio");
for (var i = 0; i < elem.length; i++) {
if (elem[i].checked) {
alertgroup = elem[i].value;
}
}
alert('alertgroup ' + alertgroup);
var rowsPerPageElem = document.getElementById("rowsPerPage");
var rowsPerPage = rowsPerPageElem.value;
alert(' rowsPerPage ' + rowsPerPage);
if (!isInteger(rowsPerPage)) {
alert('Rows per page should be an integer. It is set to the default value of 20');
rowsPerPage = 20;
}
var chkelem = document.getElementById("includingUnassignedTags");
var includingUnassignedTags = chkelem.checked;
alert(' includingUnassignedTags ' + includingUnassignedTags);
window.location = "Prod?rowsPerPage=" + rowsPerPage +
"&includingUnassignedTags=" + includingUnassignedTags + "&alertgroup=" + alertgroup;
}

function setUnassignedTags()
{
setalertgroup();
return false;
}

function postCheckbox(id, boxid, labelid) {
var elem = document.getElementById(labelid);
var checked = document.getElementById(boxid).checked;
new Ajax.Request("ProdManager", {
method: "post",
parameters: {
id: id,
boxchecked: checked
},
onComplete: function(){}
});

if (checked)
elem.style.color = 'green';
else
elem.style.color = 'red';
}

function refresh() {
window.location.reload(true);
}

function timedRefresh(timeoutPeriod) {
setTimeout("refresh();", timeoutPeriod);
}
</script>

<body>
<div id="mainmenu">
<h1><spring:message code="Hw.header"/></h1>
<div id="Logo"><img src="/static/img/Logo.jpg" width="63" height="63" alt=" Sytems"></div>
</div>
<ul id="tablist">
<li class="sprite1 active"><a href="/Hw/Prod"><spring:message
code="menu.alerts"/></a></li>
<li class="sprite1"><a href="/MonitoringDBWeb/listReaders"><spring:message
code="menu.locators"/></a></li>
<li class="sprite1"><a href="/MonitoringDBWeb/listAssets"><spring:message
code="menu.assets"/></a></li>
<li class="sprite1"><a href="/MonitoringDBWeb/listCategories"><spring:message
code="menu.categories"/></a></li>
<li class="sprite1"><a href="/MonitoringDBWeb/dbadmin"><spring:message
code="menu.administration"/></a></li>
<li class="sprite1"><a href="/MonitoringDBWeb/displayReadMe"><spring:message
code="menu.readme"/></a></li>
</ul>

<form name="alertform" method="get">
<spring:message code="alert.choice"/>
<c:choose>
<c:when test="${alertgroup == 'all'}">
<input type="radio" name="alertradio" value="all" CHECKED onClick="setalertgroup()" /> <spring:message code="alert.all"/>
<input type="radio" name="alertradio" value="ack" onClick="setalertgroup()" /> <spring:message code="alert.ack"/>
<input type="radio" name="alertradio" value="unack" onClick="setalertgroup()" /> <spring:message code="alert.unack"/>
</c:when>
<c:when test="${alertgroup == 'ack'}">
<input type="radio" name="alertradio" value="all" onClick="setalertgroup()" /> <spring:message code="alert.all"/>
<input type="radio" name="alertradio" value="ack" CHECKED onClick="setalertgroup()" /> <spring:message code="alert.ack"/>
<input type="radio" name="alertradio" value="unack" onClick="setalertgroup()" /> <spring:message code="alert.unack"/>
</c:when>
<c:when test="${alertgroup == 'unack'}">
<input type="radio" name="alertradio" value="all" onClick="setalertgroup()" /> <spring:message code="alert.all"/>
<input type="radio" name="alertradio" value="ack" onClick="setalertgroup()" /> <spring:message code="alert.ack"/>
<input type="radio" name="alertradio" value="unack" CHECKED onClick="setalertgroup()" /> <spring:message code="alert.unack"/>
</c:when>
<c:otherwise>
<input type="radio" name="alertradio" value="all" CHECKED onClick="setalertgroup()" /> <spring:message code="alert.all"/>
<input type="radio" name="alertradio" value="ack" onClick="setalertgroup()" /> <spring:message code="alert.ack"/>
<input type="radio" name="alertradio" value="unack" onClick="setalertgroup()" /> <spring:message code="alert.unack"/>
</c:otherwise>
</c:choose>

<c:set var="untagchk" value="" />
<c:if test="${includingUnassignedTags}">
<c:set var="untagchk" value="checked" />
</c:if>
&nbsp;&nbsp;&nbsp;&nbsp;
<input type="checkbox" name="includingUnassignedTags" id="includingUnassignedTags" ${untagchk} onClick="setUnassignedTags()"><spring:message code="alert.unassignedtags"/>
&nbsp;&nbsp;&nbsp;&nbsp;
<spring:message code="alert.number"/>${totalalerts}
<c:if test="${numPages > 0}">
&nbsp;&nbsp;&nbsp;&nbsp;<spring:message code="alert.page"/>${pageNumber} <spring:message code="alert.of"/> ${numPages}
</c:if>
<table class="resizable">
<thead>
<tr>
<th><spring:message code="alert.id"/></th>
<th><spring:message code="alert.date"/></th>
<th><spring:message code="alert.time"/></th>
<th><spring:message code="alert.reader"/></th>
<th><spring:message code="alert.asset"/></th>
<th><spring:message code="alert.description"/></th>
<th><spring:message code="alert.alert"/><br></br>
<spring:message code="alert.acknowledgement"/></th>
</tr>
</thead>
<tbody>
<c:set var="boxindex" value="0" />
<c:forEach items="${alerts}" var="alert">
<tr>
<c:forEach items="${alert}" var="alertvalue" begin="0" end="5"
step="1">
<td>${alertvalue}</td>
</c:forEach>
<!-- ${alert[0]} : ID -->
<!-- ${alert[6]} : the checked attribute -->
<c:set var="spanid" value="span${alert[0]}" />

<c:if test="${alert[6] == 'checked'}">
<c:set var="format_start" value="<span id='${spanid}' class='fg-green'>" />
</c:if>
<c:if test="${alert[6] == 'unchecked'}">
<c:set var="format_start" value="<span id='${spanid}' class='fg-red'>" />
</c:if>
<td><c:set var="boxindex" value="${boxindex+1}" />
<c:set var="boxid" value="box${alert[0]}" />
<c:out value="${format_start}" escapeXml="false" />
<input type="checkbox" name="checkboxChoice" id="${boxid}"
value="${alert[0]}"
${alert[6]} onClick="postCheckbox(${alert[0]}, '${boxid}', '${spanid}');">
<spring:message code="alert.ack"/>
</span></td>
</tr>
</c:forEach>

</tbody>
</table>
</form>

<c:if test="${numPages > 1}">
<div class="pageNumber">
<span class="noLink"><spring:message code="alert.page"/> </span>
<c:forEach begin="1" end="${numPages}" varStatus="status">
<c:choose>
<c:when test="${status.index==pageNumber}"><span class="noLink">${status.index}</span></c:when>
<c:otherwise><a href="Prod?page=${status.index}&alertgroup=${alertgroup}&includingUnassignedTags=${includingUnassignedTags}&rowsPerPage=${rowsPerPage}">${status.index}</a></c:otherwise>
</c:choose>
</c:forEach>
</div>
</c:if>

<div id="rowPerPageDiv">
<form name="tagform" onsubmit="setUnassignedTags()" method="get">
<input type="hidden" name="currPage" value="${currPage}"/>
<spring:message code="alert.rowsperpage"/><input type="text" name="rowsPerPage" id="rowsPerPage" value="${rowsPerPage}" />
<input type="submit" value="Apply"><br>
</form>
</div>

<hr><center><font size="-1"><spring:message code="Hw.trademark"/></font> <a href="http://www.systems.com/" title="Hw">
<img border="0" src="/static/img/systems.gif" title="Hw"
alt=" Systems"></a> </center>
</body>
</html>

Kuriyama
06-04-2010, 08:15 AM
It's been awhile since I have done anything with Spring, but your JSP appears to not have any errors in it. I did notice that you are using JavaScript to edit some form settings. It's possible that your JavaScript is causing this problem.

If you want to test it out for sure you can use something like the tamper data plugin for firefox to see exactly what the request before Java code begins processing the request.

albertkao
06-04-2010, 04:38 PM
It's been awhile since I have done anything with Spring, but your JSP appears to not have any errors in it. I did notice that you are using JavaScript to edit some form settings. It's possible that your JavaScript is causing this problem.

If you want to test it out for sure you can use something like the tamper data plugin for firefox to see exactly what the request before Java code begins processing the request.

Tamper data plugin for firefox display the following but I still don't know how to fix my program.
Should I rewrite my page with the Spring SimpleFormController?
17:29:21.978[0ms][total 0ms] Status: pending[]
GET http://127.0.0.1:8080/Comp/Prod?rowsPerPage=202&includingUnassignedTags=false&alertgroup=ack Load Flags[LOAD_DOCUMENT_URI LOAD_INITIAL_DOCUMENT_URI ] Content Size[unknown] Mime Type[unknown]
Request Headers:
Host[127.0.0.1:8080]
User-Agent[Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 (.NET CLR 3.5.30729)]
Accept[text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8]
Accept-Language[en-us,en;q=0.5]
Accept-Encoding[gzip,deflate]
Accept-Charset[ISO-8859-1,utf-8;q=0.7,*;q=0.7]
Keep-Alive[115]
Connection[keep-alive]
Referer[http://127.0.0.1:8080/Comp/Prod?rowsPerPage=201&includingUnassignedTags=false&alertgroup=ack]
Cookie[s5cookie=%7B%22alertgroup%22%3A%20%22all%22%2C%20%22rowsPerPage%22%3A%20%22%22%2C%20%22includingUnas signedTags%22%3A%20true%7D]


17:29:21.982[0ms][total 0ms] Status: pending[]
GET http://127.0.0.1:8080/Comp/Prod?rowsPerPage=202&includingUnassignedTags=false&alertgroup=ack Load Flags[LOAD_DOCUMENT_URI LOAD_INITIAL_DOCUMENT_URI ] Content Size[unknown] Mime Type[unknown]
Request Headers:
Host[127.0.0.1:8080]
User-Agent[Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 (.NET CLR 3.5.30729)]
Accept[text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8]
Accept-Language[en-us,en;q=0.5]
Accept-Encoding[gzip,deflate]
Accept-Charset[ISO-8859-1,utf-8;q=0.7,*;q=0.7]
Keep-Alive[115]
Connection[keep-alive]
Referer[http://127.0.0.1:8080/Comp/Prod?rowsPerPage=201&includingUnassignedTags=false&alertgroup=ack]
Cookie[s5cookie=%7B%22alertgroup%22%3A%20%22all%22%2C%20%22rowsPerPage%22%3A%20%22%22%2C%20%22includingUnas signedTags%22%3A%20true%7D]


17:29:21.984[54ms][total 193ms] Status: 200[OK]
GET http://127.0.0.1:8080/Comp/Prod?currPage=1&rowsPerPage=202 Load Flags[LOAD_DOCUMENT_URI LOAD_INITIAL_DOCUMENT_URI ] Content Size[-1] Mime Type[text/html]
Request Headers:
Host[127.0.0.1:8080]
User-Agent[Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 (.NET CLR 3.5.30729)]
Accept[text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8]
Accept-Language[en-us,en;q=0.5]
Accept-Encoding[gzip,deflate]
Accept-Charset[ISO-8859-1,utf-8;q=0.7,*;q=0.7]
Keep-Alive[115]
Connection[keep-alive]
Referer[http://127.0.0.1:8080/Comp/Prod?rowsPerPage=201&includingUnassignedTags=false&alertgroup=ack]
Cookie[s5cookie=%7B%22alertgroup%22%3A%20%22all%22%2C%20%22rowsPerPage%22%3A%20%22%22%2C%20%22includingUnas signedTags%22%3A%20true%7D]
Response Headers:
Server[Apache-Coyote/1.1]
Pragma[no-cache]
Expires[Thu, 01 Jan 1970 00:00:00 GMT]
Cache-Control[no-cache, no-store]
Content-Type[text/html;charset=ISO-8859-1]
Content-Language[en]
Transfer-Encoding[chunked]
Date[Fri, 04 Jun 2010 21:29:22 GMT]