Replies inline below.
On May 18, 2007, at 10:01 AM, Saptarshi Newyork wrote:
Hi,My first question is regarding display an image from JSP when the image is stored in Marklogic server.I have tried 2 things in the JSP as listed below:1. (No Result - Red cross mark in place of the image. Server could not execute the xqy file)<image width="400" height="300" src="get-img-jpeg.xqy?uri={fn:base-uri(doc("c:/100_2754.JPG")))"/>
This should work, generally speaking. There are two
potential issues I see.
1) Assuming this is HTML, the element name should be "img"
rather than "image".
2) Remember that a relative URL in the "src" attribute is
going to be relative to the page it appears in (from the browser's
perspective). To use "get-img-jpeg.xqy" anywhere in the hierarchy
of your site, you may need to make it relative to the root by
added a slash: "/get-img-jpeg.xqy".
Here I have tried to call a XQY file with the input of the uri of the image. The XQY file has the code like the following:module "http://www.w3.org/2003/05/xpath-functions" let $uri := xdmp:get-request-field("uri") return (xdmp:set-response-content-type("image/jpeg"), doc($uri))
As Jason pointed out, this XQuery should not contain the "module" declaration, it needs to be a main module.
It does not show me the image. I want to know
i) How can I call an xqy file from a JSP?
You are doing so above by referencing an XQuery module in the "src" attribute of an "img" tag (assuming the module is defined properly). You can also use the JSP tag library as you did below and invoking a module with xdmp:invoke(). The current version of the JSP tag library does not support invoking modules directly by name, although the syntax for it is defined. Now that 3.2 is out and the Mark Logic User Conference is over, I will try to add that missing piece relatively soon.
ii) Can I define XQY functions inside a JSP? What will be the syntax?
The body of an xq:query tag can contain anything that can be placed in an xdmp:eval(). You can define functions there, but they will only live for the duration of the call from JSP to server. Code that you want to re-use should be defined in server-side modules and invoked. You have the right idea above, you just need to debug why it isn't working as expected.
2. (return nothing) <xq:execute > <xq:query> let $uri := fn:base-uri(doc("100_2754.JPG"))return (xdmp:set-response-content-type("image/jpeg"), doc ($uri))</xq:query> </xq:execute>
There are two things to note here. One is that the JSP tags talk to an XDBC port on the server. If you don't have exactly the same modules path and database configured there that you do on the HTTP app server port you were using above, it may not be able to find the query may not work as expected. Second, the current version of the JSP tag library presumes that any output produced will be textual. Binary data in most cases will not pass through without being mangled. That is something else I hope to address Real Soon Now.
I don't want to store the images in the file system and want to store them in marklogic. Please tell what shall be the right way to solve this problem.Please also let me know if it is possible to define xquery function in the JSP and call XQY from JSp?
You should define your XQuery functions as .xqy files in the modules directory on the server side. You can invoke them from JSPs. It should be possible to call an XQuery module to return a binary image by referencing it in an "img" tag. You can also use the tag library to execute XQuery code, but that option is not yet guaranteed to work for binary output.
Thanks in advance, Regards, Saptarshi It's here! Your new message! Get new email alerts with the free Yahoo! Toolbar. _______________________________________________ General mailing list [email protected] http://xqzone.com/mailman/listinfo/general
--- Ron Hitchens [EMAIL PROTECTED] 650-655-2351
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ General mailing list [email protected] http://xqzone.com/mailman/listinfo/general
