tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jack Lauman <jlau...@nwcascades.com>
Subject Re: JSTL/JSP/regexp Question
Date Wed, 01 Dec 2004 18:50:03 GMT
Tim:

This app is deployed with JBoss 3.2.7RC1/Tomcat 5.0.28.  The JDK is 
1.4.2_06.
The custom tag libraries were developed using JSTL 1.0.  I'm not sure how to
convert them.  Can you use a 1.0 tag in 1.1?  Below is an example of an 
SMTP mail
tag the I'm using.  Will this work in 1.1 or does it need to be rewritten?

Thanks,

Jack

package com.nwc.tags;

import java.io.IOException;
import java.io.PrintStream;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.BodyTagSupport;

import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;

import sun.net.smtp.SmtpClient;

/**
 * @jsp.tag name="sendmail"
 *          body-content="JSP"
 *          description="Sends mail to a standard SMTP server i.e. sendmail"
 * @version 1.15, 11/17/04
 */
public class SendMailTag
    extends BodyTagSupport {
   
    private transient String smtpEL;
    private transient String toEL;  
    private transient String fromEL;
    private transient String subjectEL;
    private transient String body;

    /**
     * @jsp.attribute
     *     required="true"
     *     rtexprvalue="false"
     *     type="java.lang.String"
     *
     * @param smtp sets <code>smtp</code> to the FQDN or IP address of 
the SMTP server to use.
     */
    public void setSmtp(String smtp) {
        smtpEL = smtp;
    }

    /**
     * @jsp.attribute
     *     required="true"
     *     rtexprvalue="false"
     *     type="java.lang.String"
     *
     * @param to sets <code>to</code> to the email recipients email address.
     */
    public void setTo(String to) {
        toEL = to;
    }

    /**
     * @jsp.attribute
     *     required="true"
     *     rtexprvalue="false"
     *     type="java.lang.String"
     *
     * @param from sets <code>from</code> to the senders email address.
     */
    public void setFrom(String from) {
        fromEL = from;
    }

    /**
     * @jsp.attribute
     *     required="true"
     *     rtexprvalue="false"
     *     type="java.lang.String"
     *
     * @param subject <code>subject</code> to the subject of the email 
message.
     */
    public void setSubject(String subject) {
        subjectEL = subject;
    }


    /**
     * @return EVAL_BODY_BUFFERED
     * @throws JspException
     * (non-Javadoc)
     * @see javax.servlet.jsp.tagext.BodyTagSupport#doStartTag()
     */
    public int doStartTag() throws JspException {
        return EVAL_BODY_BUFFERED;
    }


    /**
     * @return SKIP_BODY
     * @throws JspException
     * (non-Javadoc)
     * @see javax.servlet.jsp.tagext.BodyTagSupport#doAfterBody()
     */
    public int doAfterBody() throws JspException {
        BodyContent bc = getBodyContent();
        // get the bodycontent as string
        if (bc != null) {
            body = bc.getString();
        } else {
            body = "";
        }

        return SKIP_BODY;
    }


    /**
     * @return EVAL_PAGE
     * @throws JspException
     * (non-Javadoc)
     * @see javax.servlet.jsp.tagext.BodyTagSupport#doEndTag()
     */
    public int doEndTag() throws JspException {
        /*
             * Evaluate the EL expression, if any
         */
        String smtp = (String)
                ExpressionEvaluatorManager.evaluate("name", smtpEL,
                        String.class, this, pageContext);
        String to = (String)
                ExpressionEvaluatorManager.evaluate("to", toEL,
                        String.class, this, pageContext);
        String from = (String)
                ExpressionEvaluatorManager.evaluate("from", fromEL,
                        String.class, this, pageContext);
        String subject = (String)
                ExpressionEvaluatorManager.evaluate("subject", subjectEL,
                        String.class, this, pageContext);

        // Send the mail

        try {
            SmtpClient client = new SmtpClient(smtp);
            client.from(from);
            client.to(to);
            PrintStream message = client.startMessage();
            message.println("To: " + to);
            message.println("Subject: " + subject);
            message.println(body);
            client.closeServer();
        } catch (IOException e) {
            System.out.println("ERROR SENDING EMAIL:" + e);
        }

        return EVAL_PAGE;
    }

    /**
     * Releases all instance variables.
     *
     * @see javax.servlet.jsp.tagext.TagSupport#release()
     */
    public void release() {
        smtpEL = null;
        toEL = null;
        fromEL = null;
        super.release();
    }
}


Tim Funk wrote:

> Ideally you'd be using tomcat5. (and jdk1.4) Then you can use JSTL 
> functions like below ...
>
> <function>
>   <name>match</name>
>   <function-class>my.Foo</function-class>
>   <function-signature>boolean match(java.lang.String,
>                                     java.lang.String)
>   </function-signature>
>   <example>
>     <c:if test='${fn:match("more", "r.")}'>
>   </example>
> </function>
>
> ------
> package my;
> public class Foo {
>    public static boolean match(String s, String regex) {
>        return s.matches(regex);
>    }
> }
>
>
> -Tim
>
> Jack Lauman wrote:
>
>> I'm using the following code to return results from drop down menues 
>> and user input text.
>> It works fine as long as the text is an exact case sensitive match to 
>> the data record.
>>
>> What I want to do is evaluate the output the results of a user input 
>> search based on
>> 'param.field' in figure 3.  i.e. If 'param.field' = 'name' use a 
>> regex or some other method
>> to return all records  that are a partial, case insensitive match to 
>> the input 'value' that
>> was submitted in the search request.  Is this possible to accomplish 
>> in JSTL?  If so I'd
>> like to know how.
>>
>> Thanks,
>>
>> Jack
>>
>>
>> Example1:
>> JavaScript Funciton:
>>
>> function MM_jumpMenu(targ,selObj,restore, field){ //v3.0
>> eval(targ+".location='http://mydomain.com/filter.jsp?field="+field+"&value="+selObj.

>> options[selObj.selectedIndex].value+"'");
>> if (restore) selObj.selectedIndex=0;
>> }
>> //-->
>> </script>
>>
>>
>> Example 2:
>> Form to submit the input and the field 'name' to be found in the bean 
>> created array:
>>
>> <form name="selectName" method="get" 
>> action="http:mydomain.com/filter.jsp">
>> <input type="hidden" name="field" value="name">
>> <input type="text" name="value" size="16" maxlength="40" value="">
>> <input type="image" border="0" alt="Go!" src="images/go.gif" 
>> align="absmiddle" width="22" height="23"  
>> onChange="MM_jumpMenu('parent',this,0,'name')">
>> <nwc:filterOptions which="name"/>
>> </form>
>>
>>
>> Example 3:
>> Display the results.  JSTL gets the results form a Map/Array of the 
>> entire record set that the bean
>> created.  (restaurant.id is the PK)
>>
>> <c:forEach items="${restaurantInfo.restaurants}" var="restaurant">
>> <c:set target="${restaurant}" property="filterField" 
>> value="${param.field}"/>
>> <c:if test="${restaurant.filterValue eq param.value}">
>> <tr>
>> <td width="155" align="center">
>> <div align="left"><a 
>> href="http://mydomain.com/viewRestaurant.jsp?id=<c:out 
>> value="${restaurant.id}"/>"><c:out 
>> value="${restaurant.name}"/></a></div>
>> </td>
>> <td width="130">
>> <div align="left"><c:out value="${restaurant.address1}"/></div>
>> </td>
>> <td width="79">
>> <div align="left"><c:out value="${restaurant.city}"/></div>
>> </td>
>> <td width="107">
>> <div align="right"><c:out value="${restaurant.reservationPhone}"/></div>
>> </td>
>> </tr>
>> </c:if>
>> </c:forEach>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message