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 paulbrickell <pa...@evolvedintelligence.com> on 2009/09/15 10:48:59 UTC

import tag for dynamic content

Does anyone know how to use the import tag to access dynamic content from the
current context?

I naively thought this would do it...

<c:set var="url" value="/x/y/z"/>
<c:import url="${url}" var="xml" />

or

<c:set var="url" value="x/y/z"/>
<c:import url="${url}" var="xml" />


Where /x/y/z is a (context)relative path that my application maps to a
servlet. However this doesn't seem to work because the import tag doesn't
expand the url and make a request. It does, to be honest, what it's name
suggests it should and just tries to import the content statically from the
given path.

Actually I am trying to import xml for parsing here, but it seems that the
xml parse tag only works upon a document in some scope and not against a
URL. So I appear to be a bit stuck. 

I found this...

<c:set var="xmlURL"
value="${pageContext.request.scheme}://${pageContext.request.serverName}:${pageContext.request.serverPort}${pageContext.request.contextPath}/x/y/z"/>
<c:import url="${xmlURL}" var="xml" />

and it works. But I cannot believe this is the right way to it.

TIA,
Paul B.
-- 
View this message in context: http://www.nabble.com/import-tag-for-dynamic-content-tp25450335p25450335.html
Sent from the Taglibs - User mailing list archive at Nabble.com.


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


Re: import tag for dynamic content

Posted by Jeremy Boynes <jb...@apache.org>.
As I read the spec, something like this should work:
	<c:set var="url" value="/x/y/z"/>
	<c:import var="doc" url="${url}"/>
	<x:parse varDom="dom" doc="${doc}"/>

The <c:import> should dispatch to the servlet at "/x/y/z" in your application and store the response in ${doc} as a String. The <x:parse> should then parse that String into a Document stored in ${dom}.

If that's not working for you can you open a bug (ideally with something to reproduce the error or best of all a patch) and I'll look in to it.
Thanks
Jeremy

On Jul 29, 2010, at 3:03 AM, paulbrickell wrote:

> 
> Then you're not doing it the way I have described.
> 
> I have been battling with this for ages. Every time I want to import
> dynamically generated xml document it doesn't work. The URL gets mangled by
> the import tag.
> 
> I can use the request parameters to form a full URL but that doesn't work
> for a secure app because the credentials aren't shared.
> 
> Create a Jersey web service and use the tags as I have described. Just
> doesn't work at all. I have resorted to writing my own tag. 
> 
> Hey ho.
> 
> 
> 
> Hassan Schroeder-2 wrote:
>> 
>> On Wed, Sep 16, 2009 at 7:05 AM, paulbrickell
>> <pa...@evolvedintelligence.com> wrote:
>> 
>>> If I create a url with a context relative path (e.g. /x/y/z) and the I
>>> use
>>> this in the url attribute of an import tag, the import tag seems to
>>> attempt
>>> a lookup of a file in the web application.
>>> 
>>> So given this...
>>> 
>>> <c:url var="aURL" value="/x/y/z"/>
>>> ${aURL} Get resource at z
>>> <c:import url="${aURL}" var="xml" />
>>> 
>>> The link in href attribute in the browser is a valid url, but the url
>>> attribute in the import tag is not. I get a file not found exception for
>>> /x/y/z. Import seems to want to lookup a static resource (html page for
>>> example) located on the file system and not open connection to some
>>> network
>>> resource. I am assuming from the name (import) that this is probably what
>>> is
>>> expected.
>> 
>> No, what you're describing works exactly correctly for me -- the
>> URL is accessed, and the rendered output, not a file, is fetched.
>> 
>> What value does ${aURL} display?
>> -- 
>> Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
>> twitter: @hassan
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
>> 
>> 
>> 
> 
> -- 
> View this message in context: http://old.nabble.com/import-tag-for-dynamic-content-tp25450335p29294887.html
> Sent from the Taglibs - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-user-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: taglibs-user-help@tomcat.apache.org
> 


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


Re: import tag for dynamic content

Posted by paulbrickell <pa...@evolvedintelligence.com>.
Then you're not doing it the way I have described.

I have been battling with this for ages. Every time I want to import
dynamically generated xml document it doesn't work. The URL gets mangled by
the import tag.

I can use the request parameters to form a full URL but that doesn't work
for a secure app because the credentials aren't shared.

Create a Jersey web service and use the tags as I have described. Just
doesn't work at all. I have resorted to writing my own tag. 

Hey ho.



Hassan Schroeder-2 wrote:
> 
> On Wed, Sep 16, 2009 at 7:05 AM, paulbrickell
> <pa...@evolvedintelligence.com> wrote:
> 
>> If I create a url with a context relative path (e.g. /x/y/z) and the I
>> use
>> this in the url attribute of an import tag, the import tag seems to
>> attempt
>> a lookup of a file in the web application.
>>
>> So given this...
>>
>> <c:url var="aURL" value="/x/y/z"/>
>> ${aURL} Get resource at z
>> <c:import url="${aURL}" var="xml" />
>>
>> The link in href attribute in the browser is a valid url, but the url
>> attribute in the import tag is not. I get a file not found exception for
>> /x/y/z. Import seems to want to lookup a static resource (html page for
>> example) located on the file system and not open connection to some
>> network
>> resource. I am assuming from the name (import) that this is probably what
>> is
>> expected.
> 
> No, what you're describing works exactly correctly for me -- the
> URL is accessed, and the rendered output, not a file, is fetched.
> 
> What value does ${aURL} display?
> -- 
> Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
> twitter: @hassan
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/import-tag-for-dynamic-content-tp25450335p29294887.html
Sent from the Taglibs - User mailing list archive at Nabble.com.


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


Re: import tag for dynamic content

Posted by Hassan Schroeder <ha...@gmail.com>.
On Wed, Sep 16, 2009 at 7:05 AM, paulbrickell
<pa...@evolvedintelligence.com> wrote:

> If I create a url with a context relative path (e.g. /x/y/z) and the I use
> this in the url attribute of an import tag, the import tag seems to attempt
> a lookup of a file in the web application.
>
> So given this...
>
> <c:url var="aURL" value="/x/y/z"/>
> ${aURL} Get resource at z
> <c:import url="${aURL}" var="xml" />
>
> The link in href attribute in the browser is a valid url, but the url
> attribute in the import tag is not. I get a file not found exception for
> /x/y/z. Import seems to want to lookup a static resource (html page for
> example) located on the file system and not open connection to some network
> resource. I am assuming from the name (import) that this is probably what is
> expected.

No, what you're describing works exactly correctly for me -- the
URL is accessed, and the rendered output, not a file, is fetched.

What value does ${aURL} display?
-- 
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
twitter: @hassan

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


Re: import tag for dynamic content

Posted by paulbrickell <pa...@evolvedintelligence.com>.
Hassan,

If I create a url with a context relative path (e.g. /x/y/z) and the I use
this in the url attribute of an import tag, the import tag seems to attempt
a lookup of a file in the web application.

So given this...

<c:url var="aURL" value="/x/y/z"/>
${aURL} Get resource at z 
<c:import url="${aURL}" var="xml" />

The link in href attribute in the browser is a valid url, but the url
attribute in the import tag is not. I get a file not found exception for
/x/y/z. Import seems to want to lookup a static resource (html page for
example) located on the file system and not open connection to some network
resource. I am assuming from the name (import) that this is probably what is
expected. Doesn't help me though.

If I set the value in the URL to /x/y/z.html (assuming that resource exists)
all is well. So the question is can I 'import' dynamic content (from a
servlet in my case) rather than a static resource?

I guess I could point my URL to a JSP that 'includes' the content I want,
assuming that include works properly. I still think I am missing something.

Cheers,
Paul B.



Hassan Schroeder-2 wrote:
> 
> On Wed, Sep 16, 2009 at 12:43 AM, paulbrickell
> <pa...@evolvedintelligence.com> wrote:
> 
>> Agreed. Just doesn't work.
> 
> ? Uh, "doesn't work" exactly how?
> 
> This
>    <c:url var="xmlURL" value="/x/y/z"/>
> sets `xmlURL`  to a very different value compared to your original
>    <c:set var="url" value="x/y/z"/>
> 
> What's the exact error?
> -- 
> Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
> twitter: @hassan
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/import-tag-for-dynamic-content-tp25450335p25473112.html
Sent from the Taglibs - User mailing list archive at Nabble.com.


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


Re: import tag for dynamic content

Posted by Hassan Schroeder <ha...@gmail.com>.
On Wed, Sep 16, 2009 at 12:43 AM, paulbrickell
<pa...@evolvedintelligence.com> wrote:

> Agreed. Just doesn't work.

? Uh, "doesn't work" exactly how?

This
   <c:url var="xmlURL" value="/x/y/z"/>
sets `xmlURL`  to a very different value compared to your original
   <c:set var="url" value="x/y/z"/>

What's the exact error?
-- 
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
twitter: @hassan

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


Re: import tag for dynamic content

Posted by paulbrickell <pa...@evolvedintelligence.com>.
Hassan,

Agreed. Just doesn't work.


Hassan Schroeder-2 wrote:
> 
> On Tue, Sep 15, 2009 at 1:48 AM, paulbrickell
> <pa...@evolvedintelligence.com> wrote:
>>
>> Does anyone know how to use the import tag to access dynamic content from
>> the
>> current context?
> 
>> I found this...
>>
>> <c:set var="xmlURL"
>> value="${pageContext.request.scheme}://${pageContext.request.serverName}:${pageContext.request.serverPort}${pageContext.request.contextPath}/x/y/z"/>
>> <c:import url="${xmlURL}" var="xml" />
>>
>> and it works. But I cannot believe this is the right way to it.
> 
>   <c:url var="xmlURL" value="/x/y/z"/>
> 
> would be easier :-)
> 
> -- 
> Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
> twitter: @hassan
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: taglibs-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: taglibs-user-help@jakarta.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/import-tag-for-dynamic-content-tp25450335p25467489.html
Sent from the Taglibs - User mailing list archive at Nabble.com.


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


Re: import tag for dynamic content

Posted by Hassan Schroeder <ha...@gmail.com>.
On Tue, Sep 15, 2009 at 1:48 AM, paulbrickell
<pa...@evolvedintelligence.com> wrote:
>
> Does anyone know how to use the import tag to access dynamic content from the
> current context?

> I found this...
>
> <c:set var="xmlURL"
> value="${pageContext.request.scheme}://${pageContext.request.serverName}:${pageContext.request.serverPort}${pageContext.request.contextPath}/x/y/z"/>
> <c:import url="${xmlURL}" var="xml" />
>
> and it works. But I cannot believe this is the right way to it.

  <c:url var="xmlURL" value="/x/y/z"/>

would be easier :-)

-- 
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
twitter: @hassan

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