"Kirkdorffer, Daniel" wrote:

> Playing devil's advocate: avoid scriptlets, write a taglib tag to do the
> task!
>
> Sounds like a lot of work doesn't it.
>

Nope ... not when it's already done.  Check out tonight's nightly build of Struts
at <http://jakarta.apache.org/builds/struts/nightly>, which lets you accomplish the
original poster's purpose here by saying:

    <struts:ifParameterNull name="cid">
        <struts:redirect href="login.html"/>
    </struts:ifParameterNull>

This use case is actually pretty good evidence why custom tags are helpful.
Consider the complete text needed to accomplish this with a scriptlet:

    <%
        String cid = request.getParameter("cid");
        if ((cid == null) || (cid.length() == 0)) {
            response.sendRedirect(response.encodeRedirectURL("login.html"));
            return;
        }
    %>

How many times have you seen scripters make the following mistakes?

- Try to use "==" to compare Java strings (as in the original
  case below).

- Neglect to test for null (which will create null pointer exceptions).

- Neglect to remember the curly braces (especially if they embed
  template text in between).

- Neglect to do URL rewriting so that their sessions still work if the
  user turns cookies off.

- Neglect to do a "return" to avoid problems when the rest of the
  JSP page is flushed.

Even though I've written millions of lines of code in tens of languages (mostly
Java lately, thank goodness :-), I'd still rather let the custom tag get all of
these details right for me.

Craig



>
> Dan
>

Craig


>
> > ----------
> > From:         Chris Ernenwein[SMTP:[EMAIL PROTECTED]]
> > Reply To:     A mailing list about Java Server Pages specification and
> > reference
> > Sent:         Monday, June 12, 2000 1:48 PM
> > To:   [EMAIL PROTECTED]
> > Subject:      Re: If condition in jsp
> >
> > try
> >   if (request.getParameter("cid") != null) {
> >     // blah blah
> > }
> >
> > -----Original Message-----
> > From: A mailing list about Java Server Pages specification and reference
> > [mailto:[EMAIL PROTECTED]]On Behalf Of Kuklani Mahesh
> > Sent: Monday, June 12, 2000 10:37 AM
> > To: [EMAIL PROTECTED]
> > Subject: If condition in jsp
> >
> >
> > Hi ,
> >     I am new to jsp and want to design a form. The form has 2 fields id
> > and
> > password. I want to check in jsp whether if the field is null then
> > re-direct
> > him to login.html again. Below is my code, if i am sending blank id field
> > still i am getting hello printed on the browser but i want it to redirect
> > to
> > login page.
> >
> > login.jsp
> >
> > <html>
> > <head>
> > <title> Login Successfull </title>
> > </head>
> > <body>
> > <%@ page language="java" %>
> > <% String id = request.getParameter("cid") ;
> >    if(id =="" || id == " " || id == "  ")
> >     {
> >
> > response.sendRedirect("D:\\jswdk\\jswdk-1.0.1\\examples\\WEB-INF\\servlets
> > \\
> > login.html") ;
> >     }
> >     else
> >     { %>
> >
> >     Hello <%=request.getParameter("cid") %>
> >     <% } %>
> > </body>
> > </html>
> >
> > Thanks in advance.
> >
> > Mahesh.
> >
> > ==========================================================================
> > =
> > To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> > JSP-INTEREST".
> > Some relevant FAQs on JSP/Servlets can be found at:
> >
> >  http://java.sun.com/products/jsp/faq.html
> >  http://www.esperanto.org.nz/jsp/jspfaq.html
> >  http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> >  http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
> >
> > ==========================================================================
> > =
> > To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> > JSP-INTEREST".
> > Some relevant FAQs on JSP/Servlets can be found at:
> >
> >  http://java.sun.com/products/jsp/faq.html
> >  http://www.esperanto.org.nz/jsp/jspfaq.html
> >  http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> >  http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
> >
>
> ===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.html
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to