Imugi
Imugi

Reputation: 161

How to send parameters with JSP?

I have an index jsp. How can I send parameters to some bean from the index page so that the second page genereted some data depending on the sent parameters ?


Here is my 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>

my 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>

and my 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 says: org.apache.jasper.JasperException: PWC6054: Cannot find any information on property 'name' in a bean of type 'A.a'

What's wrong ? Why do my program do not work ??

Upvotes: 1

Views: 59

Answers (1)

Mart&#237;n Schonaker
Mart&#237;n Schonaker

Reputation: 7305

It expects a property in the Java bean jargon, i.e. you should provide these methods:

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

public String getName() { ... }

Upvotes: 2

Related Questions