views:

35

answers:

1

I am using Jboss and Netbeans to create Spring MVC web application on windows. it runs on http://localhost/myapplication/

My project path is D:\Myapplication\

My JSP Views are in D:\Myapplication\web\jsp\

My Javascripts are in D:\Myapplication\web\js\

Controllers are in D:\Myapplication\web\src\java\controller\

I have created 1 controller which needs to create a HTML file at javascript location i.e. D:\Myapplication\web\js\

I am using Jquery.sheet to create a web spreadsheet. and I want to use this HTML to load the Jquery.sheet for this i just want that Relative URL of that HTML stored in JAVASCRIPT location.

A: 

That depends on the request URL of the page for which jQuery.sheet is been executed.

First check in the browser address bar the absolute URL of the webpage which uses jQuery.sheet. It may be for example http://localhost/myapplication/jsp/page.jsp.

Then check/test in the browser address bar the absolute URL of the generated HTML file in question. It may be for example http://localhost/myapplication/js/generated.html.

The common path for both is only one folder level up: ../ which will end up in http://localhost/myapplication. From there you can just access the JS folder and the generated HTML file by js/generated.html.

Summarized, the relative URL you need is ../js/generated.html.


Update: as per the comment it turns out that you've elaborated your problem in a completely different perspective. You were talking about URL's in client side perspective while you actually meant about local disk file system paths at the server side. In that case, just use ServletContext#getRealPath() to convert a relative web path to an absolute disk file system path.

String relativeWebPath = "/js";
String absoluteDiskPath = servletContext.getRealPath(relativeWebPath);
File generatedHtml = new File(absoluteDiskPath, "generated.html");
BalusC
Actualy I am not able to create the html file in the http://localhost/myapplication/js/ using relative path.I can hard-code the path in windows and create the html file.But I want to create the HTML file in such a way that the file gets stored in the http://localhost/myapplication/js/ folder in both windows and Linux and should be accessible easily.Then I can use the relative URL for the HTML file as you suggested.The execution path for my project is C:\Program Files\NetBeans\NetBeans 6.8Thank you.
Prasen Revankar