如何使用JSP发送参数?

时间:2016-01-26 16:21:30

标签: jsp

我有一个索引jsp。如何从索引页面向某个bean发送参数,以便第二页根据发送的参数生成一些数据?

这是我的index.jsp:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Hello World! qqqqq</h1>
        <form name="Input Name Form" action="response.jsp"/>
        <p> Enter your name:</p>
           <input type="text" name="name"/>  
           <input type="submit"   value="ok" />
    </form>

    </body>
</html>

我的response.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Hello World!</h1>
        <jsp:useBean id="aaa" scope="page" class="A.a" />
        <jsp:setProperty name="aaa" property="name" value="<%= request.getParameter("set")%>" />
        <jsp:getProperty name="aaa" property="name" />

    </body>
</html>

和我的A.a bean:

public class a {
    public a ()
    {}
    private String name;

    /**
     * @return the name
     */
    public String get() {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void set(String name) {
        this.name = name;
    }
}

GlassFish说: org.apache.jasper.JasperException:PWC6054:在'A.a'类型的bean中找不到有关属性'name'的任何信息

怎么了?为什么我的程序不起作用?

1 个答案:

答案 0 :(得分:2)

它期望Java bean术语中有property,即你应该提供以下方法:

public void setName(String s) { ... }

public String getName() { ... }