前言
當在我們注冊用戶時,如果給前臺的提示是用戶名重復并且用戶名太長時,就會要往action里面添加多個errors,這時到前臺怎么把它依次拿出來
下面話不多說了,來一起看看詳細的介紹吧
方法如下
①找到配置文件
struts2-core-2.3.35.jar/template/simple/fielderror.ftl(不同版本的文件路徑大同小異)
②創建新的文件包并拷貝文件
在項目根目錄下創建template.simple并將fielderror.ftl拷貝過來
此時根目錄下的fielderror.ftl文件優先權大于默認的fielderror.ftl文件
③修改拷貝過來的fielderror.ftl文件
修改前文件如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
<#-- /* * $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>刪除
修改后文件如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
<#-- /* * $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
總結
以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,如果有疑問大家可以留言交流,謝謝大家對服務器之家的支持。
原文鏈接:http://www.cnblogs.com/zhanghongcan/p/9753917.html