修改struts中:fielderror.ftl 模板

来源:互联网 发布:小学语文教学软件 编辑:程序博客网 时间:2024/05/20 08:24

在项目登录页面:

当验证码输入有误时,应该提示:验证码输入有误,请重新输入,但是页面出现乱了!


错误原因:


在产生错误信息时,页面中增加了<ul> <li><span></span></li></ul>标签,该如何修改改,

解决方法(一):

在项目的src下,新建文件夹:template.simple,在文件夹里面放修改好的fielderror.ftl文件。


fielderror.ftl 代码:

<#--/* * $Id: fielderror.ftl 805635 2009-08-19 00:18:54Z musachy $ * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements.  See the NOTICE file * distributed with this work for additional information * regarding copyright ownership.  The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License.  You may obtain a copy of the License at * *  http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied.  See the License for the * specific language governing permissions and limitations * under the License. */--><#if fieldErrors??><#t/><#assign eKeys = fieldErrors.keySet()><#t/><#assign eKeysSize = eKeys.size()><#t/><#assign doneStartUlTag=false><#t/><#assign doneEndUlTag=false><#t/><#assign haveMatchedErrorField=false><#t/><#if (fieldErrorFieldNames?size > 0) ><#t/><#list fieldErrorFieldNames as fieldErrorFieldName><#t/><#list eKeys as eKey><#t/><#if (eKey = fieldErrorFieldName)><#t/><#assign haveMatchedErrorField=true><#t/><#assign eValue = fieldErrors[fieldErrorFieldName]><#t/><#if (haveMatchedErrorField && (!doneStartUlTag))><#t/><ul<#rt/><#if parameters.id?if_exists != ""> id="${parameters.id?html}"<#rt/></#if><#if parameters.cssClass??> class="${parameters.cssClass?html}"<#rt/><#else> class="errorMessage"<#rt/></#if><#if parameters.cssStyle??> style="${parameters.cssStyle?html}"<#rt/></#if>><#assign doneStartUlTag=true><#t/></#if><#t/><#list eValue as eEachValue><#t/><li><span>${eEachValue}</span></li></#list><#t/></#if><#t/></#list><#t/></#list><#t/><#if (haveMatchedErrorField && (!doneEndUlTag))><#t/></ul><#assign doneEndUlTag=true><#t/></#if><#t/><#else><#t/><#if (eKeysSize > 0)><#t/><ul<#rt/><#if parameters.cssClass??> class="${parameters.cssClass?html}"<#rt/><#else> class="errorMessage"<#rt/></#if><#if parameters.cssStyle??> style="${parameters.cssStyle?html}"<#rt/></#if>><#list eKeys as eKey><#t/><#assign eValue = fieldErrors[eKey]><#t/><#list eValue as eEachValue><#t/><#if parameters.escape>${eEachValue!?html}<#else>${eEachValue!}</#if></#list><#t/></#list><#t/></ul></#if><#t/></#if><#t/></#if><#t/>
这样,就ok了,重新发布项目,看结果如下:


解决方法(二):

也可以在jsp页面中修改,效果是一样的。代码如下:

<TR><span style="white-space:pre"></span><TD class="td">验 证 码:</TD><TD class="td"><input name="checkNum" type="text" value="" id="checkNum" style="width: 80"><span style="white-space:pre"></span><img id="checkNumImage" src="${pageContext.request.contextPath}/image.jsp" height="19" align="absmiddle" onClick="changeCheckNum()"  title="点击换一张" style="cursor:hand">
<span style="white-space:pre"></span></TD><span style="white-space:pre"></span><td><s:fielderror fieldName="checkNum"/></td>
</TR>
把错误提示信息和验证码,图片放在一行里面。

0 0
原创粉丝点击