欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

addFieldError无法匹配的报错

程序员文章站 2022-03-18 13:02:46
public void validate() { if(getname()== null || getname().length()==0) { add...
public void validate()
	{
		if(getname()== null || getname().length()==0)
		{
			addfielderror("newbookname","用户名不为空");
		}
		else{
			try{
				db mysql = new db();
				username = mysql.returnlogin(request);
				rs = mysql.selectfri(request, username, this.getname());
				if(rs.next())
				{
					addfielderror("name","已经存在");
					
				}
			}catch(sqlexception ex)
			{
				ex.printstacktrace();
			}
		}
		//if(getisbn()==null|| getisbn().length()==0)
			//addfielderror("","bunengweikong");
	}
	
	public string execute() throws exception{
		db mysql = new db();
		username = mysql.returnlogin(request);
		string fri = mysql.insertfri(request, username, this.getname(), this.getprice(), this.getdate(), this.getauthor(), this.getpublisher(), this.getisbn(),this.getnumber());
		if(fri.equals("ok"))
		{
			message = success;
		}
		else if(fri.equals("one"))
		{
			message = input;
			
		}
		return message;
	}

上部分message =success;和addfielderror报错无法匹配

the method addfielderror(string, string) is undefined for the type addfriaction

主要原因使在public class 定义的时候没有增加exteds 和implements

修改:

public class addfriaction extends actionsupport implements servletrequestaware {

之后就可以正常调用了

void com.opensymphony.xwork2.actionsupport.addfielderror(string fieldname, string errormessage)