struts2中simple主题下<s:fieldError>标签默认样式的移除方法

 更新时间:2018年10月11日 08:40:54   作者:努力学习的IT萌新  
这篇文章主要给大家介绍了关于struts2中simple主题下<s:fieldError>标签默认样式的移除方法,文中通过示例代码介绍的非常详细,需要的朋友可以参考借鉴,下面随着小编来一起学习学习吧

前言

当在我们注册用户时,如果给前台的提示是用户名重复并且用户名太长时,就会要往action里面添加多个errors,这时到前台怎么把它依次拿出来

下面话不多说了,来一起看看详细的介绍吧

方法如下

①找到配置文件

struts2-core-2.3.35.jar/template/simple/fielderror.ftl(不同版本的文件路径大同小异)

②创建新的文件包并拷贝文件

在项目根目录下创建template.simple并将fielderror.ftl拷贝过来

此时根目录下的fielderror.ftl文件优先权大于默认的fielderror.ftl文件

③修改拷贝过来的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

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对脚本之家的支持。

相关文章

  • Springboot框架整合添加redis缓存功能

    Springboot框架整合添加redis缓存功能

    缓存就是一个存储器,在技术选型中,常用 Redis 作为缓存数据库。缓存主要是在获取资源方便性能优化的关键方面。Redis 是一个高性能的 key-value 数据库,接下来通过本文给大家介绍Springboot框架整合添加redis缓存功能,感兴趣的朋友一起看看吧
    2021-11-11
  • Java面试之如何获取客户端真实IP

    Java面试之如何获取客户端真实IP

    这篇文章主要给大家介绍了关于Java面试之如何获取客户端真实IP的相关资料,文中通过示例代码介绍的非常详细,对大家学习或者使用Java具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
    2019-09-09
  • SpringBoot自定义注解使用读写分离Mysql数据库的实例教程

    SpringBoot自定义注解使用读写分离Mysql数据库的实例教程

    这篇文章主要给大家介绍了关于SpringBoot自定义注解使用读写分离Mysql数据库的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-11-11
  • SpringMVC访问静态资源的方法

    SpringMVC访问静态资源的方法

    本篇文章主要介绍了SpringMVC访问静态资源的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-02-02
  • Springboot详解如何实现SQL注入过滤器过程

    Springboot详解如何实现SQL注入过滤器过程

    这篇文章主要介绍了基于springboot实现SQL注入过滤器,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2022-06-06
  • Java常用字节流和字符流实例汇总

    Java常用字节流和字符流实例汇总

    这篇文章主要介绍了Java常用字节流和字符流实例汇总,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2020-07-07
  • Java中JDBC连接数据库详解

    Java中JDBC连接数据库详解

    本文主要介绍了JDBC连接数据库的相关知识,具有很好的参考价值。下面跟着小编一起来看下吧
    2017-03-03
  • Springboot项目全局异常统一处理案例代码

    Springboot项目全局异常统一处理案例代码

    最近在做项目时需要对异常进行全局统一处理,主要是一些分类入库以及记录日志等,因为项目是基于Springboot的,所以去网络上找了一些博客文档,然后再结合项目本身的一些特殊需求做了些许改造,现在记录下来便于以后查看
    2023-01-01
  • java正则表达式获取指定HTML标签的指定属性值且替换的方法

    java正则表达式获取指定HTML标签的指定属性值且替换的方法

    下面小编就为大家带来一篇java正则表达式获取指定HTML标签的指定属性值且替换的方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2016-12-12
  • Java多线程Thread类的使用及注意事项

    Java多线程Thread类的使用及注意事项

    这篇文章主要介绍了Java多线程Thread类的使用及注意事项,在java标准库中提供了一个Thread类来表示/操作线程,Thread类也可以视为是java标准库提供的API
    2022-06-06

最新评论