I am using Tomcat7 on Windows Server 2008.
I have the following two lines in my JSP page
<apptags:SQLIteratorTag query="<%=myQuery%>">
</apptags:SQLIteratorTag>
If myQuery returns at least one row, then my JSP page behaves normally.
If myQuery returns no rows, then my JSP page copies some text from the page (e.g. the contents of a combobox) and duplicates it!
My thoughts are as follows: Since the combobox that it copies from is populated by a query, it seems that in the absence of a query returning results, the page seems to grab the results of a different query.
Has anyone got any ideas how to solve this?
Thanks!
Scriptlets
<%...%>in a JSP body are oftenly messy. They can be fully avoided by using JSTL@taglibwith EL${...}, which is the clean and highly recommended way to iterate your query results in JSP.Download jstl-api.jar and jstl-impl.jar, put them in your lib folder and add to the top of the page:
For the query part, leave all the processing to a Java class, storing the query results in a variable
myListof typeListand sending it (get/post forward) to your page, which should only show the values and nothing else:This should be enough to avoid unexpected behaviours in your page. It’ll simply do nothing if there’s no rows. But if you still wanna check that, you wouldn’t have to do the query again, since its results are already inside
myList:Or use
${noCompanySelected}instead of${fn:length(myList) != 0}, if that’s really your condition.…Other things you may want to verify:
Your
myQueryis being reused by something else, somewhere else in your application… or recursively twice by the same page if you createdmyQueryin the session instead of request.Also, if your taglib
apptagswas made by yourself, another possibility is that it’s manipulating tags it shouldn’t.