'jsp:getProperty'无法在类型为package.Class错误的bean中找到有关属性'name'的任何信息

时间:2017-07-03 10:29:48

标签: java jsp servlets javabeans getproperty

我正在尝试实现jsp:useBean标记。以下是以下文件。将执行简单的名称检索。

的index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Title</title>
</head>
<body>
<form action="Controller.do" method="post">
Enter Name: <input type="text" name="userName"><br>
<input type="submit" name="Submit">
</form>
</body>
</html>

Controller.java类

package foo;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Controller extends HttpServlet{

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {

    String s=req.getParameter("userName");
    PersonEmployee p=new PersonEmployee();
    p.setName(s);
    req.setAttribute("person",p);

    RequestDispatcher view=req.getRequestDispatcher("result.jsp");
    view.forward(req, resp);
}
}

我故意使用辅助类来检查通过JSP保存和检索。

PersonEmployee.java

package foo;

public class PersonEmployee {

private String name;

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

public String getName() {
    return name;
}

}

我在以下jsp文件中收到错误。 错误:[在'foo.Controller'类型的bean中找不到有关属性'name'的任何信息 我仍然无法识别'getproperty'标签的'name'属性中的错误。

result.jsp中

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<jsp:useBean id="person" class="foo.Controller" scope="request"/>
Name is: <jsp:getProperty name="person" property="name"/>
</body>
</html>

0 个答案:

没有答案