[nbj2ee] Problem injecting form parameters into java bean

  • From: < >
  • To:
  • Subject: [nbj2ee] Problem injecting form parameters into java bean
  • Date: Sat, 31 Mar 2012 03:23:42 +0000 (GMT)

Hello,

I am facing a problem I cannot solve without help :

I have a very simple test application : one jsp, one bean and one
servlet and I am trying to inject the request parameters into my java
bean using the <jsp:useBean/> and
<jsp:setParameter/> tags.

I am usign the latest Glassfish server 3.1.1 and Java EE 6
specifications.

My files go like this :

1) My test JSP :

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<jsp:useBean id="usager" class="entites.Usager" scope="session" />
<jsp:setProperty name="usager" property="*"/>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
        <title>Page TEST</title>
    </head>
    <body>
        <h1>Please input something!</h1>
        <p></p>
        <form action="Valider" method="post" >
            <input type="text"  name="champ" value="" size="20" />
            <button type="submit" value="Valider" name="Valider" 
>Cliquez ici!</button>
        </form>
    </body>
</html>

2) The bean, wih only one field :

package entites;
 
public class Usager {
 
    private String champ;
 
    public String getChamp() {return champ;}
 
    public void setChamp(String champ) {
        this.champ = champ;
    }
 
}

3) The processRequest method of the Servlet :

    protected void processRequest(HttpServletRequest request,
HttpServletResponse response)
            throws ServletException, IOException {
        HttpSession laSession = request.getSession(true);
        Usager usager = (Usager) laSession.getAttribute("usager");
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet Valider</title>");
            out.println("</head>");
            out.println("<body>");
 
            out.println("[Valider] La javaBean «usager» a été récupérée
de la session.");
            out.println("<br/>");
            out.println("Champ = " + usager.getChamp());
 
            out.println("</body>");
            out.println("</html>");
        } finally {
            out.close();
        }
    }

4) My output :

[Valider] La javaBean «usager» a été récupérée de la session. 
Champ = null

In other words, the request parameter did not get injected into the
bean.

What did I do wrong?  Any help would be appreciated...

Thank you,

Pierre

[nbj2ee] Problem injecting form parameters into java bean

pierrecaron2 03/31/2012

Project Features

About this Project

www was started in November 2009, is owned by jpirek, and has 21 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20140418.2d69abc). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close