struts2中simple主題下<s:fieldError>標(biāo)簽?zāi)J(rèn)樣式的移除方法
前言
當(dāng)在我們注冊(cè)用戶時(shí),如果給前臺(tái)的提示是用戶名重復(fù)并且用戶名太長(zhǎng)時(shí),就會(huì)要往action里面添加多個(gè)errors,這時(shí)到前臺(tái)怎么把它依次拿出來(lái)
下面話不多說(shuō)了,來(lái)一起看看詳細(xì)的介紹吧
方法如下
①找到配置文件
struts2-core-2.3.35.jar/template/simple/fielderror.ftl(不同版本的文件路徑大同小異)
②創(chuàng)建新的文件包并拷貝文件
在項(xiàng)目根目錄下創(chuàng)建template.simple并將fielderror.ftl拷貝過(guò)來(lái)
此時(shí)根目錄下的fielderror.ftl文件優(yōu)先權(quán)大于默認(rèn)的fielderror.ftl文件
③修改拷貝過(guò)來(lái)的fielderror.ftl文件
修改前文件如下
<#-- /* * $Id$ * * 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?has_content> id="${parameters.id?html}"<#rt/> </#if> <#if parameters.cssClass?has_content> class="${parameters.cssClass?html}"<#rt/> <#else> class="errorMessage"<#rt/> </#if> <#if parameters.cssStyle?has_content> style="${parameters.cssStyle?html}"<#rt/> </#if> > <#assign doneStartUlTag=true><#t/> </#if><#t/> <#list eValue as eEachValue><#t/> <li><span><#if parameters.escape>${eEachValue!?html}<#else>${eEachValue!}</#if></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?has_content> class="${parameters.cssClass?html}"<#rt/> <#else> class="errorMessage"<#rt/> </#if> <#if parameters.cssStyle?has_content> style="${parameters.cssStyle?html}"<#rt/> </#if> > <#list eKeys as eKey><#t/> <#assign eValue = fieldErrors[eKey]><#t/> <#list eValue as eEachValue><#t/> <li><span><#if parameters.escape>${eEachValue!?html}<#else>${eEachValue!}</#if></span></li> </#list><#t/> </#list><#t/> </ul> </#if><#t/> </#if><#t/> </#if><#t/>
將<ul></ul>、<li></li>、<span></span>刪除
修改后文件如下
<#-- /* * $Id$ * * 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/> <#assign doneStartUlTag=true><#t/> </#if><#t/> <#list eValue as eEachValue><#t/> <#if parameters.escape>${eEachValue!?html}<#else>${eEachValue!}</#if> </#list><#t/> </#if><#t/> </#list><#t/> </#list><#t/> <#if (haveMatchedErrorField && (!doneEndUlTag))><#t/> <#assign doneEndUlTag=true><#t/> </#if><#t/> <#else><#t/> <#if (eKeysSize > 0)><#t/> <#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/> </#if><#t/> </#if><#t/> </#if><#t/>
重啟tomcat
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,如果有疑問(wèn)大家可以留言交流,謝謝大家對(duì)腳本之家的支持。
相關(guān)文章
Maven和IntelliJ IDEA搭建多模塊微服務(wù)的實(shí)現(xiàn)
本文主要介紹了Maven和IntelliJ IDEA搭建多模塊微服務(wù)的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2024-05-05mybatis框架xml下trim中的prefix與suffix等標(biāo)簽的用法
這篇文章主要介紹了mybatis框架xml下trim中的prefix與suffix等標(biāo)簽的用法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-07-07一文搞懂如何實(shí)現(xiàn)Java,Spring動(dòng)態(tài)啟停定時(shí)任務(wù)
定時(shí)任務(wù)的應(yīng)用場(chǎng)景十分廣泛,如定時(shí)清理文件、定時(shí)生成報(bào)表、定時(shí)數(shù)據(jù)同步備份等。本文將教你實(shí)現(xiàn)Java、Spring動(dòng)態(tài)啟停定時(shí)任務(wù),感興趣的可以學(xué)習(xí)一下2022-06-06基于CopyOnWriteArrayList并發(fā)容器(實(shí)例講解)
下面小編就為大家?guī)?lái)一篇基于CopyOnWriteArrayList并發(fā)容器(實(shí)例講解)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-11-11