在设置对象中找不到符号

时间:2015-03-01 19:17:31

标签: java

编译时,出现错误。我很困惑。任何帮助表示赞赏!

Error mesage is:src\com\example\Testerx.java:21: cannot find symbol
symbol  : method setDog(foo.Dog)
location: class foo.Employee
p.setDog(dog);

Employee上课:

package foo;

public class Employee {
    public Employee() {}

    String name = "";

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    String empID = "1122";

    public void setEmpID(String empID) {
        this.empID = empID;
    }

    public String getEmpID() {
        return empID;
    }

    Dog dog = null;

    public Dog getDog() {
        return dog;
    }

    public void setDog(Dog dog) {
        this.dog = dog;
    }
}

Testerx上课:

package com.example;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class Testerx extends HttpServlet {
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws  IOException, ServletException {
        String name = request.getParameter("userName");
        // request.setAttribute("name",name);
        foo.Employee p = new foo.Employee();
        p.setName("Evan");
        foo.Dog dog = new foo.Dog();
        dog.setName("Spike");
        p.setDog(dog);
        request.setAttribute("person", p);
        RequestDispatcher view = request.getRequestDispatcher("/result4.jsp");
        view.forward(request, response);
    }
}

Dog上课:

package foo;

import java.io.*;
import java.util.*;

public class Dog {
    private String name = "";

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

0 个答案:

没有答案