admin管理员组

文章数量:1355532

i tried to disable auto plete(autoplete="off") in struts framework,the process i followed is 1)In Strut-html.tld file i had few attributes of TextTag so added autoplete attribute

<tagclass>org.apache.struts.taglib.html.TextTag</tagclass>
<attribute>
<name>autoplete</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>   
</attribute>

2)i wrote a class for customtag by extending org.apache.struts.taglib.html.TextTag

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 autoplete = null;

public String getAutoplete()
{ return autoplete; }

public void setAutoComplete(String autoplete)
{
this.autoplete = autoplete; 

} 

protected void prepareOtherAttributes(StringBuffer sb) { 


if (autoplete != null) { 

sb.append(" autoplete=\""+autoplete+"\""); 
}
}
}

3) And in jsp page i added autoplete="off" attribute

so when i run my application im getting the following error

/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" %>

Some one please help me to solve this error and i tried with javascript as well but its not working.

function DisableAutoplete()
{
var AC_Disable_login=document.forms[0].elements['loginID'];
AC_Disable_login.setAttribute ("autoplete", "off");
}

i tried to disable auto plete(autoplete="off") in struts framework,the process i followed is 1)In Strut-html.tld file i had few attributes of TextTag so added autoplete attribute

<tagclass>org.apache.struts.taglib.html.TextTag</tagclass>
<attribute>
<name>autoplete</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>   
</attribute>

2)i wrote a class for customtag by extending org.apache.struts.taglib.html.TextTag

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 autoplete = null;

public String getAutoplete()
{ return autoplete; }

public void setAutoComplete(String autoplete)
{
this.autoplete = autoplete; 

} 

protected void prepareOtherAttributes(StringBuffer sb) { 


if (autoplete != null) { 

sb.append(" autoplete=\""+autoplete+"\""); 
}
}
}

3) And in jsp page i added autoplete="off" attribute

so when i run my application im getting the following error

/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" %>

Some one please help me to solve this error and i tried with javascript as well but its not working.

function DisableAutoplete()
{
var AC_Disable_login=document.forms[0].elements['loginID'];
AC_Disable_login.setAttribute ("autoplete", "off");
}
Share Improve this question edited Jun 11, 2014 at 8:03 JayanthSuresh asked Jun 11, 2014 at 6:45 JayanthSureshJayanthSuresh 1011 silver badge5 bronze badges 6
  • Format the code properly. – Braj Commented Jun 11, 2014 at 6:46
  • Hi Braj, i think the code is properly formatted now. – JayanthSuresh Commented Jun 11, 2014 at 7:02
  • Still some alignment issues are there but no problem it looks better than previous. – Braj Commented Jun 11, 2014 at 7:03
  • It might help you. Read form/input tags and turning off autoplete – Braj Commented Jun 11, 2014 at 7:04
  • Thanks for the link,Even i tried in the same way but it is showing the same error. – JayanthSuresh Commented Jun 11, 2014 at 7:27
 |  Show 1 more ment

3 Answers 3

Reset to default 3

You do not need to rewrite Struts 1.x to add this functionality. All you need is to add the following lines:

<script src="//code.jquery./jquery-1.11.1.min.js"></script>
<script>
    $(function(){
        $(":text").attr("autoplete", "off");
    });
</script>

There is a quick and dirty hack documented here http://www.coderanch./t/54020/Struts/form-input-tags-turning-autoplete that embeds the autoplete option inside another form element.

For example

<html:form method="post\" autoplete=\"off" action="verify_login.do" >

Struts renders as

<form name="LoginForm" method="post" autoplete="off" action="verify_login.do">

Its not pretty but it saves the need to redefine Struts taglibs.

I have tried many solutions 1. including the dirty hack given above, 2. setting autoplete off for form by calling a script at page load:

    <body class="article-page auxillary-page" onload="autopletion()">
 function autopletion()
 {
         for (i=0; i<document.forms.length; i++) {
         document.forms[i].setAttribute("AutoComplete","off");
        }
 }

and few others, None of them seems to work.. I think the only solution is: change your tag to html tag, and then in submit function for form assign that value to your required bean property.

you can use

<input type="password" name="password1" maxlength="4" size="25" readonly onfocus="this.removeAttribute('readonly');" autoplete="off" />

This worked for me on struts 1 , J7 Eclipse keplar, wildfly server.

本文标签: javascriptDisable Autocomplete(autocompletequotoffquot) using STRUTSStack Overflow