use*_*104 5 javascript jsp jstl custom-tags struts-1
我试图在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>
Run Code Online (Sandbox Code Playgroud)
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+"\"");
}
}
}
Run Code Online (Sandbox Code Playgroud)
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" %>
Run Code Online (Sandbox Code Playgroud)
有人请帮助我解决这个错误,我尝试使用javascript但它不起作用.
function DisableAutocomplete()
{
var AC_Disable_login=document.forms[0].elements['loginID'];
AC_Disable_login.setAttribute ("autocomplete", "off");
}
Run Code Online (Sandbox Code Playgroud)
您不需要重写 Struts 1.x 来添加此功能。您所需要的只是添加以下行:
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<script>
$(function(){
$(":text").attr("autocomplete", "off");
});
</script>
Run Code Online (Sandbox Code Playgroud)