See below.

Sreekumar Pillai wrote:

> well.. thanks for all the responses. You guys are great. At least I am
> learning a lot.
>
> On the same thread, can I do something like this? When the user hits submit,
> I am redirecting back to the same page, executes <jsp:setProperty, and then
> forwarding to the Model2Servlet.
>
> <jsp:useBean id="theAddressBean" scope="session"
> class="CMBeans.CMAddressBean"/>
>
> <jsp:setProperty name="theAddressBean" property="*"/>
>
> <%
>   if ( request.getParameter( "submit") != null )
>   {
>     <jsp:forward page="/servlet/Model2Servlet" />
>      return;
>   }
> %>
>
> <form action="thispage.jsp">  --> submit to itself
> <input type=text name=userName>
> <input type=password name=password>
> <input type=submit name="submit" value="submit">
> </form>
>
> 1. I want to use the best of JSP and Servlets. jsp:setProperty tag is very
> useful when you have a page with considerable form input parameters. I don't
> have to get all the parameters from the request object and then set to the
> appropriate bean and then save to the session  object. If I have 20/30
> pages, this can be a lot of code.
>

<jsp:setProperty>, especially with the "*" modifier, is certainly useful -- but
it's not magic.  You can write a utility class in Java to emulate this
functionality, using the reflection API, in about 100 lines of code or so and then
re-use this for all your beans in the model 2 servlet.  After all, that's all the
JSP-generated code really does.

>
> 2. If I use the Servlet to do all the processing (Model2Servlet), if I ever
> change my form input names, I have to change the servlet too. I don't see a
> clear separation of presentation layer from the business logic layer. If we
> use the jsp:setProperty tag, the change in form input names result a change
> in the bean object only. Oh! well.. all the objects which use the bean too.
> Not a whole lot of difference, but still. And, functionally the Beans act as
> the agent/data Carriers between Servlets and JSPs.
>

See above -- you can emulate the "*" modifier with a single Java utility class,
and accomplish the same freedom from code changes when you change input
properties.

>
> 3. Can I do something like this in the Model2Servlet?
>
>      HttpSession session = request.getSession(true);
>      UserInfoBean uib = (UserInfoBean) session.getValue("theUserInfoBean");
>      if (uib == null)
>          session.putValue("theUserInfoBean", uib);
>
>     JspRuntimeLibrary.introspect( theAddressBean, request );
>

That's exactly the kind of thing I'm suggesting, except that there's nothing in
the portable servlet/JSP API like it.  I've seen people post simple versions of
this method on SERVLET-INTEREST.  You could also go "borrow" the relevant code
from an open source JSP implementation like Jakarta has
(http://jakarta.apache.org).

>
> Thanks
> Sree
>

Craig

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