File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Referring XML in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Referring XML in JSP" Watch "Referring XML in JSP" New topic

Referring XML in JSP

ganesh malkar

Joined: May 03, 2006
Posts: 1
I have a web project and its folder structure is as follows in exploded form :-


The above is the level in which the resources are present in the exploded form. Now I want to refer batch.xml in the javascript code and want to convert the xml in string.

What I have done..

<script language="JavaScript" type="text/javascript">
var path = <%= request.getContextPath()/jsps/batch/batch.xml%>
var xmlInString = vendorObj.convertXmlToString(path);

When I promote this code to tomcat server, the function convertXmlToString() [vendor code, dont have source code] is unable to get the batch.xml and throws NullPointerException.

What I am missing here?
J. Kevin Robbins

Joined: Dec 16, 2010
Posts: 1522

That ugly scriptlet code (I won't beat you up for that; I'll leave that to Bear) is not going to return the correct path. Think about what getContextPath() returns and then look at the rest of the path that you are appending. Something is missing.

<cue Bear on the use of 20th century coding techniques>

"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." -- Ted Nelson
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

If I understand your folder hierarchy correctly, it looks like you're trying to access something from within the application's WEB-INF folder. And since it's Javascript you're asking about, that means you are asking to access that from the client side. Which can't be done, even if your code did produce the right URL. (Just because a JSP generates the Javascript, that makes no difference.)
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63865

J. Kevin Robbins wrote:<cue Bear on the use of 20th century coding techniques>

At this point I'll just let this JspFaq entry talk for me.

Why people aren't serious about their craft is a mystery to me.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: Referring XML in JSP
jQuery in Action, 3rd edition