tags:

views:

210

answers:

2

Hello, Here is my problem, I'm bulding a modular aplication, and I'm using the SwitchAction in the struts-config.xml to change to another config file, eht problem is that when I change to the other module, and get back to the default config xml, I'm getting a error, because my page use a AJAX request to get some data from the DB, and I've found out that the prefix that I first send to change the module is getting back and its return the wrong url. following is a example to better undestanding:

Page modulos.vm, accessing the new's link, new's link have the prefix "new" so its acessing the page in the "new" module with this URL "/new/new.do", accessing the new.vm without a problem, accessing modulos.vm again, the AJAX function should be "/admin/modulos.do?somedata", but the URL that is returning is "/new/admin/modulos.do", and I dont know what to do, accordling withe the struts documentation "prefix - The module prefix (beginning with "/") of the module to which control should be switched. Use a zero-length string for the default module. The appropriate ModuleConfig object will be stored as a request attribute, so any subsequent logic will assume the new module."

So anyone have any idea why AJAX is including the "new" in the URL? or anyone have any idea on how to clear up the relative path or something that may help me?

Almost forget to mention I'm using JQuery to call the AJAX function.

+1  A: 

You need to use absolute rather than relative URLs. At the moment your JavaScript is building a relative URL based on the current context path.

If you're using JSP you could put this in your header:

<script type="text/javascript">
var CONTEXT_PATH = "<%= request.getContextPath() %>";
</script>

And then when you make the AJAX call, you need to build the URL like so:

$.post(CONTEXT_PATH + '/admin/modulos.do'....)

This is what I do if I need to get the context path into JavaScript - then just use it wherever I need to make an AJAX call to the server.

Phill Sacre
A: 

Well I'm using velocity, and I don't know how to get the context path in it. Do you know how? Oh other thing in the action that the AJAX function call I'm using request.getServletPath(); and its return the "/new/admin/modulo.do".