On Jan 19, 4:48 pm, "Peter Michaux" <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I'm experimenting with server-side JavaScript using Rhino. I have
> written some bits of JavaScript that wrap Java objects. One example is
> a HttpServletRequest. If I have a request object and do
>
> var path = request.getPathInfo();
>
> the path variable seems to have a java.lang.String value. When I try
> to call any of the JavaScript string methods I get an error. It seems
> I need to perform some type conversion or wrapping. What I've been
> doing just to get by is
>
> var path = request.getPathInfo() + '';
>
> This seems non-optimal. What is the best way to make this type
> conversion or wrap the java.lang.String?
>
> I've tried exposing Context.javaToJS as a global function in my
> "shell" with the following code
>
> public static Object javaToJS(Context cx, Scriptable thisObj,
> Object[] args, Function funObj)
> {
> return Context.javaToJS(args[0], getTopLevelScope(thisObj));
> }
>
> When I call this function in JavaScript with a Java string argument
> the returned result is not a JavaScript string.
>
> What to do?
>
> Thanks,
> Peter
Easiest is to call String(), like String(request.getPathInfo()).
--N
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino