You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by TIMO EINSIEDLER-BURGER <TI...@DIN.DE> on 2002/05/24 18:02:49 UTC

Need some help on encoding URLs

Hello you people,

maybe someone knows: 

why does the var $1 get evaluated in this code (or how do i address it alright so it would get evaluated, as it obviously seems to be out of scope!?):

(jsp-code)
<rx:regexp id="rx4">s/href="(?!http:)(.*?)"/<%= response.encodeURL("$1") %>"/gmi</rx:regexp>

(generated servlet code:
                do {
                // end
                // HTML // begin [file="/db_mbhw.jsp";from=(196,20);to=(196,44)]
                    out.write("s/href=\"(?!http:)(.*?)\"/");

                // end
                // begin [file="/db_mbhw.jsp";from=(196,47);to=(196,73)]
                    out.print( response.encodeURL("$1") );
                // end
                // HTML // begin [file="/db_mbhw.jsp";from=(196,75);to=(196,80)]
                    out.write("\"/gmi");

                // end
                // begin [file="/db_mbhw.jsp";from=(196,80);to=(196,92)]
                } while (_jspx_th_rx_regexp_3.doAfterBody() == javax.servlet.jsp.tagext.BodyTag.EVAL_BODY_AGAIN);
)

and not in this one ?

(jsp-code)
<rx:regexp id="rx3">s/href="(?!http:)(.*)"/href="generic_import.jsp?url=<%= java.net.URLEncoder.encode("$1") %>"/gmi</rx:regexp>

(generated servlet code:
                do {
                // end
                // HTML // begin [file="/db_mbhw.jsp";from=(194,20);to=(194,71)]
                    out.write("s/href=\"(?!http:)(.*)\"/href=\"genric_import.jsp?url=");

                // end
                // begin [file="/db_mbhw.jsp";from=(194,74);to=(194,108)]
                    out.print( java.net.URLEncoder.encode('$1') );
                // end
                // HTML // begin [file="/db_mbhw.jsp";from=(194,110);to=(194,115)]
                    out.write("\"/gmi");

                // end
                // begin [file="/db_mbhw.jsp";from=(194,115);to=(194,127)]
                } while (_jspx_th_rx_regexp_2.doAfterBody() == javax.servlet.jsp.tagext.BodyTag.EVAL_BODY_AGAIN);
)

basically, what i need to do, is to parse an imported resource and take specific hrefs and modify them so they would hand over their values as a parameter to another jsp, which imports that given param (the original url).
You see the problem why i need encoding looks like this: href="generic_import.jsp?url_param=original_url?p1=value1&p2=value2" 

ps: maybe there is also a tag that would do the task, but for example <c:urlencode> is deprecated, <c:url> only seems to rewrite and i did not come across another similar solution !

thanx in advance for your kind help.

timo einsiedler-burger


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Need some help on encoding URLs

Posted by Glenn Nielsen <gl...@voyager.apg.more.net>.
You can't embed dynamic code with scriptlets or tags that are run when
the regexp is applied in a substitue. The dynamic code can only be used
for creating the string used for the regexp.


TIMO EINSIEDLER-BURGER wrote:

> Hello you people,
> 
> maybe someone knows: 
> 
> why does the var $1 get evaluated in this code (or how do i address it alright so it would get evaluated, as it obviously seems to be out of scope!?):
> 
> (jsp-code)
> <rx:regexp id="rx4">s/href="(?!http:)(.*?)"/<%= response.encodeURL("$1") %>"/gmi</rx:regexp>
> 
> (generated servlet code:
>                 do {
>                 // end
>                 // HTML // begin [file="/db_mbhw.jsp";from=(196,20);to=(196,44)]
>                     out.write("s/href=\"(?!http:)(.*?)\"/");
> 
>                 // end
>                 // begin [file="/db_mbhw.jsp";from=(196,47);to=(196,73)]
>                     out.print( response.encodeURL("$1") );
>                 // end
>                 // HTML // begin [file="/db_mbhw.jsp";from=(196,75);to=(196,80)]
>                     out.write("\"/gmi");
> 
>                 // end
>                 // begin [file="/db_mbhw.jsp";from=(196,80);to=(196,92)]
>                 } while (_jspx_th_rx_regexp_3.doAfterBody() == javax.servlet.jsp.tagext.BodyTag.EVAL_BODY_AGAIN);
> )
> 
> and not in this one ?
> 
> (jsp-code)
> <rx:regexp id="rx3">s/href="(?!http:)(.*)"/href="generic_import.jsp?url=<%= java.net.URLEncoder.encode("$1") %>"/gmi</rx:regexp>
> 
> (generated servlet code:
>                 do {
>                 // end
>                 // HTML // begin [file="/db_mbhw.jsp";from=(194,20);to=(194,71)]
>                     out.write("s/href=\"(?!http:)(.*)\"/href=\"genric_import.jsp?url=");
> 
>                 // end
>                 // begin [file="/db_mbhw.jsp";from=(194,74);to=(194,108)]
>                     out.print( java.net.URLEncoder.encode('$1') );
>                 // end
>                 // HTML // begin [file="/db_mbhw.jsp";from=(194,110);to=(194,115)]
>                     out.write("\"/gmi");
> 
>                 // end
>                 // begin [file="/db_mbhw.jsp";from=(194,115);to=(194,127)]
>                 } while (_jspx_th_rx_regexp_2.doAfterBody() == javax.servlet.jsp.tagext.BodyTag.EVAL_BODY_AGAIN);
> )
> 
> basically, what i need to do, is to parse an imported resource and take specific hrefs and modify them so they would hand over their values as a parameter to another jsp, which imports that given param (the original url).
> You see the problem why i need encoding looks like this: href="generic_import.jsp?url_param=original_url?p1=value1&p2=value2" 
> 
> ps: maybe there is also a tag that would do the task, but for example <c:urlencode> is deprecated, <c:url> only seems to rewrite and i did not come across another similar solution !
> 
> thanx in advance for your kind help.
> 
> timo einsiedler-burger
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 


-- 
----------------------------------------------------------------------
Glenn Nielsen             glenn@more.net | /* Spelin donut madder    |
MOREnet System Programming               |  * if iz ina coment.      |
Missouri Research and Education Network  |  */                       |
----------------------------------------------------------------------


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>