我尝试在struts框架中禁用自动补全(autocomplete=“off”),我遵循的过程是:1)在Strut-html.tld文件中,我几乎没有TextTag属性,所以添加了自动补全属性
<tagclass>org.apache.struts.taglib.html.TextTag</tagclass>
<attribute>
<name>autocomplete</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>2)我通过扩展org.apache.struts.taglib.html.TextTag为customtag编写了一个类
import org.apache.struts.taglib.html.TextTag.*;
public class TextTag extends org.apache.struts.taglib.html.TextTag {
private static final long serialVersionUID = 1L;
private String autocomplete = null;
public String getAutocomplete()
{ return autocomplete; }
public void setAutoComplete(String autocomplete)
{
this.autocomplete = autocomplete;
}
protected void prepareOtherAttributes(StringBuffer sb) {
if (autocomplete != null) {
sb.append(" autocomplete=\""+autocomplete+"\"");
}
}
}3),并且在jsp页面中添加了autocomplete="off“属性
因此,当我运行我的应用程序时,我得到了以下错误
/index.jsp(1): Error in using tag library uri='/tags/struts-html' prefix='html':
The Tagclass'org.apache.struts.taglib.html.FormTag' has no setter method corresponding
to TLD declared attribute 'name', (JSP 1.1 spec, 5.4.1) probably occurred due to an
error in /index.jsp line 1:
<%@ taglib uri="/tags/struts-html" prefix="html" %>有人请帮我解决这个错误,我也试着用javascript,但它不工作。
function DisableAutocomplete()
{
var AC_Disable_login=document.forms[0].elements['loginID'];
AC_Disable_login.setAttribute ("autocomplete", "off");
}发布于 2014-06-16 11:58:07
您不需要重写Struts1.x来添加此功能。您只需添加以下几行:
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<script>
$(function(){
$(":text").attr("autocomplete", "off");
});
</script>发布于 2014-09-15 15:14:26
这里记录了一个快速而肮脏的技巧,http://www.coderanch.com/t/54020/Struts/form-input-tags-turning-autocomplete将自动完成选项嵌入到另一个表单元素中。
例如
<html:form method="post\" autocomplete=\"off" action="verify_login.do" >Struts呈现为
<form name="LoginForm" method="post" autocomplete="off" action="verify_login.do">它并不美观,但它省去了重新定义Struts标记库的需要。
发布于 2017-05-22 20:04:27
我尝试了许多解决方案1.包括上面给出的肮脏的黑客,2.通过在页面加载时调用脚本来关闭表单的自动完成:
<body class="article-page auxillary-page" onload="autocompletion()">
function autocompletion()
{
for (i=0; i<document.forms.length; i++) {
document.forms[i].setAttribute("AutoComplete","off");
}
}
还有一些其他的,它们似乎都不起作用..我认为唯一的解决方案是:将您的标签更改为html标签,然后在表单的提交函数中将该值分配给您所需的bean属性。
您可以使用
<input type="password" name="password1" maxlength="4" size="25" readonly onfocus="this.removeAttribute('readonly');" autocomplete="off" />
这对我在Struts1、J7 Eclipse keplar、wildfly服务器上很有效。
https://stackoverflow.com/questions/24156275
复制相似问题