aspose file tools*
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
Author

Referring XML in JSP

ganesh malkar
Greenhorn

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

1)Tomcat
2)webapps
3)Project
4)WEB-INF
4)jsps
5)batch
6)batch.xml
5)loadBatch.jsp
4)index.jsp

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);
</script>

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
Bartender

Joined: Dec 16, 2010
Posts: 1043
    
  13

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
Bartender

Joined: Oct 14, 2005
Posts: 18904
    
    8

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
Marshal

Joined: Jan 10, 2002
Posts: 61653
    
  67

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] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Referring XML in JSP