Tips for extracting the URL from a JSP using JavaScript

When my JSP returns, it loads a JavaScript that serves as a form action when a button is clicked. This JavaScript includes a request.open() call, with the URL it needs to pass as a peer of the JSP that loaded it. The URL must be the one that was originally called. For instance, if a.jsp loads the following JavaScript:

function doSomething() { var path = "some url" + "/b.jsp?" + "params"; var request = new XMLHttpRequest(); request.open("POST", path, true); ...

In cases where I am testing a.jsp with a direct call to "http://localhost/context/a.jsp" or in an environment that redirects calls to a server not accessible from a web browser, I would like the JavaScript to use the prefix of the URL that called a.jsp before making a call to b.jsp.

Thank you

Answer №1

Perhaps consider removing the "some url" and simply passing b.jsp? This way, it might be interpreted as a relative path and navigate to the directory where your initial jsp is located.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The second request made with $.ajax is bypassed

I have been working on integrating the Google Maps JavaScript API and attempting to update a heat map when a user clicks on a specific div element. The latitude and longitude data used for the heatmap are fetched from local JSON files. While I have success ...

What is the best way to dynamically hide a textbox in JSP based on the selection of a

On my JSP page, I have a textbox and a checkbox. I attempted to use jQuery and JavaScript to hide the textbox when the checkbox is checked, but it doesn't seem to be working. Below is the code snippet: <p class="contact"> <input id="check" n ...

Column Arrangements in a Table

Is there a method to insert a new column into a table using the jQuery plugin DataTables? ...

Having trouble importing Bootstrap into Next.js? It seems like the issue may be related to the

I am currently facing an issue with importing bootstrap 5.3.2 (not react-bootstrap) into my NextJS 14.1.0 project that utilizes the new App Router. My goal is to strategically utilize individual Bootstrap components (not through data-attrs). I managed to ...

Caught up: TypeScript not catching errors inside Promises

Currently, I am in the process of developing a SPFx WebPart using TypeScript. Within my code, there is a function dedicated to retrieving a team based on its name (the get() method also returns a promise): public getTeamChannelByName(teamId: string, cha ...

Is there a way to implement an event listener for a customized select element within a table on a webpage?

I have a table that contains columns populated from a database. I also have a custom select dropdown in one of the columns, along with an update button. I want to create an event listener for the button that captures the user's selection from the cust ...

Refresh the div based on the script's output

Currently, I am struggling to make a password change form work properly as I have limited knowledge of jQuery. The form successfully changes the password, but there is no visual feedback for the user. When I submit the form, it routes to changePassword.php ...

Custom shaped corrugated sheet in three dimensions

While constructing a house-like structure with corrugated sheets, I utilized BoxGeometry to outline the structure and adjusted vertices to create a corrugated sheet wall. I have been experimenting with creating a facade using corrugated sheets in the sh ...

How to Stop Element Flickering While Hovering in Selenium IE Webdriver

My code is functioning perfectly in Firefox, but when I try it on Internet Explorer, there is flickering. Here is my code: WebElement mouseOver= driver.findElement(By.linkText("abc")); //I'm locating the element by link text. Selenium finds the ...

employing iframes dynamically to overlay a webpage

I inserted this iframe into a webpage <iframe src='http://redbug.redrocksoftware.com.au:80/Pages/chamara.html' style="position:absolute;z-index:1;" ></iframe> The chamara.html page has a button that, when clicked, should cover the c ...

"Error: Unable to push new Grade to grades array" encountered while attempting to add a Grade to an existing array

Hi there! I'm working on a webapp that allows me to track my grades and calculate the average, but I'm having trouble adding grades to my Array using a button. Whenever I click on the Add Button, an error message pops up: TypeError: this.grades. ...

Is there a way to display a message box on initial page load only, using JavaScript or jQuery?

I am looking to display a message box only once when a webpage first loads, and then not show it again if the user refreshes the page. The message should appear regardless of whether the user is logged in or not. Is using cookies the only option for achie ...

Encountering a situation where attempting to retrieve JSON data results in receiving an undefined

After fetching JSON data from the API , I successfully printed out text to the console with the correct data. However, when attempting to access any of its properties, they are returning as undefined. var url = "http://www.omdbapi.com/?t=batman&y=& ...

Regular Expressions for Strings in JavaScript

I want to create a regular expression in JavaScript that can search for patterns like ${.............}. For example, if I have a string like { "type" : "id", "id" : ${idOf('/tar/check/inof/high1')}, "details" : [ { ...

Troubleshooting the "Failed to mount component" error in Vue: fixing template or render function definition issues

Struggling with writing a Vue component, encountering the issue: Failed to mount component: template or render function not defined. Tried various fixes like adding default when importing the component, but none of them seem to work. My component code is i ...

Loading website with continuous HTML5 video playback

I'm currently working on a website that features a large section with a video background set to loop. To enhance the user experience, we decided to include a preloading image while the site loads its resources. Our current setup involves using jQuery ...

What is the best way to pass an array through router navigate function?

I've searched for a solution in other questions, but nothing has helped me... My goal is to redirect to a URL like this: this.router.navigateByUrl('/products'); I want to pass an array and retrieve it in the component with the active link ...

I'm having trouble inserting text into a three.js scene

I recently started working with three.js and I'm experimenting with some basic code. However, I keep encountering the same error message. I was under the impression that I added the object to the scene after using the loader.load function, so I'm ...

Troubleshooting incompatibility issues between Tailwindcss and NextJS 12 due to experimental features

When I first started using NextJS 12, I decided to try building a project with tailwind. This is my package.json file: { "name": "test", "version": "0.1.0", "private": true, "scripts": { ...

Having trouble importing a package into my React boilerplate

Having trouble importing the react-image-crop package with yarn and integrating it into a react boilerplate. Encountered an error after installing the package: Module parse failed: /Users/...../frontend/node_modules/react-image-crop/lib/ReactCrop.js Unex ...