Sreekumar Pillai wrote:

> 1. How do you use jsp:setProperty tag along with <form
> action=Model2Servlet>?
>
> class userInfoBean
> {
>    String userName;
>    String userpassword;
>
>    // Get and set methods for userName and password.
>    //
>    ..
> }
>
> I have a jsp page which accepts a userName and password.
>
> <jsp:useBean id="theUserInfoBean" scope="session" class="UserInfoBean"/>
>
> <form action=controllerServlet>
> <input type=text name=userName>
> <input type=password name=userpassword>
> ..
> <input type=submit name="Submit">
> </form>
>
> In Model2Servlet, I can definitely get the values from the request object or
> write a method in UserInfoBean to process the request. But I want to use
> jsp:setProperty tag to populate bean data with the form data.
>

The <jsp:setProperty> element is only useful if the destination of your form submit
is another JSP page.  Then, you would do something like this:

    <jsp:useBean id="theUserInfoBean" scope="session" class="UserInfoBean">
        <jsp:setProperty name="theUserInfoBean" property="userName"/>
        <jsp:setProperty name="theUserInfoBean" property="userpassword"/>
    </jsp:useBean>

If you are submitting to a servlet instead, you would not be doing this -- instead,
you'd be doing the servlet equivalent:

    UserInfoBean uib = new UserInfoBean(...);
    uib.setUserName(request.getParameter("userName");
    uib.setUserpassword(request.getParameter("userpassword");
    HttpSession session = request.getSession(true);
    session.putValue("theUserInfoBean", uib);

>
> Thanks in advance. Special thanks to Craig for the excellent response to my
> earlier question regarding global objects.
>
> Sree
>

Craig McClanahan

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html

Reply via email to