我们在使用JSP自定义表单标签时,发现收尾标签 </form>
总是显示在错误的位置,这给我们带来了很多问题,因为以下动态生成的html元素没有嵌套在 <form>...</form>
当用户提交表单后,这些元素的数据就会丢失。 下面是代码。
<ct:table>
<ct:form name="form1" >
<ct:addFromRequest prefix="<%= AP.CSA_PREFIX %>" />
<ct:add name="<%= AP.ACTION %>" value=" " />
<tr>
.....some dynamically generated code here
</tr>
</ct:form>
</ct:table>
在IE中,它的工作原理和预期一样。
<table>
<form name="form1" >
<tr>
...
</tr>
</form>
</table>
但在FireFox和Chrome浏览器中,它总是显示出这样的结果。
<table>
<form name="form1" ></form> *******the closing </form> tag appears here
<tr>
... dynamically generated html controls here
</tr>
</table>
整个页面的代码都在这里。
<%
CCtFormValidation ct_form = new CCtFormValidation( jsp_input );
CCtHelperFunctions ct_helper = new CCtHelperFunctions( jsp_input );
%>
<%@ include file="../../generic_gui/template/general_head.jsp" %>
<ct:script>
function CheckForm ( form_to_check )
{
if ( form_to_check.<%=AP.MANAGE_GROUP%>[0].checked
&& form_to_check.<%=AP.GROUP_ID%>.selectedIndex < 1 )
{
<%= ct_form.printErrorJavascriptAlert ( CFrontEndErrorCodes.FRONTEND_ERROR_CODE_MISSING_MANDATORY_PARAMS ) %>
form_to_check.<%=AP.GROUP_ID%>.focus();
return false;
}
return true;
}
function BeforeSubmit( form_to_submit )
{
form_to_submit.<%=AP.ACTION%>.value = "<%=AP.ACTION_SUBMIT%>";
}
function BeforeCancel( form_to_cancel )
{
form_to_cancel.<%=AP.ACTION%>.value = "<%=AP.ACTION_CANCEL%>";
}
function OnLoad()
{
}
</ct:script>
<%@ include file="../../generic_gui/template/general_body_start.jsp" %>
<ct:table width="75%">
<tr>
<td>
<ct:form name="form1">
<ct:addFromRequest prefix="<%= AP.CSA_PREFIX %>" />
<ct:add name="<%= AP.ACTION %>" value=" " />
<span class="PageHeader">
<%= rc.getStr ( "s_page_title" ) %>
</span>
</td>
</tr>
<tr>
<td colspan="3"><br><br></td>
</tr>
<tr>
<td colspan="3">
<span class="BodyText">
<%= rc.getStr ( "s_text_1" ) %>
</span>
</td>
</tr>
<tr>
<td colspan="3"><br></td>
</tr>
<tr>
<td colspan="2">
<input type="radio" name="<%=AP.MANAGE_GROUP%>" value="<%=AP.MODIFY_GROUP%>" checked>
<span class="BodyText">
<%= rc.getStr("s_modify_group_text")%>
</span>
</td>
<td>
<span class="BodyText">
<select id="<%=AP.GROUP_ID%>" name="<%=AP.GROUP_ID%>" size="1" class="textBoxNoSize" onFocus="document.form1.<%=AP.MANAGE_GROUP%>[0].checked=true;">
<OPTION value="<%=rc.getStr("s_select_group")%>"><%=rc.getStr("s_select_group")%></OPTION>
<%
CCSAGroupDetails current_group;
for ( int counter = 0 ; counter < group_list.size() ; ++counter )
{
current_group = ( CCSAGroupDetails ) group_list.get ( counter );
%>
<OPTION value="<%=current_group.getGroupId()%>"><%=current_group.getGroupName()%></OPTION>
<% } %>
</select>
</span>
</td>
</tr>
<tr>
<td colspan="3">
<input type="radio" name="<%=AP.MANAGE_GROUP%>" value = "<%=AP.CREATE_GROUP%>">
<span class="BodyText">
<%= rc.getStr("s_create_group_text")%>
</span>
</td>
</tr>
<tr>
<td colspan="3">
<br>
</td>
</tr>
<tr height="50" valign="bottom">
<td align="center">
<ct:button param="button_next" javascript="SubmitForm( document.form1 );"/></td>
<td></td>
<td align="center">
<ct:button param="button_cancel" javascript="CancelForm( document.form1 );"/></td>
</tr>
</ct:form>
</ct:table>
<%@ include file="../../generic_gui/template/general_body_end.jsp" %>
<%@ include file="../../generic_gui/template/general_footer.jsp" %>
在IE上渲染的页面,右标签开始和结束。<form name=form1>...</form>
然而,FF和Chrome的页面呈现为 <form name=form1></form>
.
我的代码有问题吗?