Jsp interacting with Javascript on a webpage - is Ajax involved?

Iā€™m currently working on a website and struggling with programming dynamic features.

The goal is for the user to input x in a textbox, click submit, process it using Java on the server side, and then display the outcome as a report to the user using JavaScript.

As of now, I am using JSP to handle users' input but I now need to transfer JSON data into the JavaScript. The JavaScript functions require JSON data to work properly.

My current setup includes JSP code that generates the required JSON data and JavaScript code that operates with hardcoded JSON data. I want to find a way to store the JSON returned by the JSP in a variable and pass it to the JavaScript. While I have a basic understanding of AJAX, I am uncertain if this integration is achievable or how to connect all the pieces together.

Any assistance would be greatly appreciated.

Answer ā„–1

You can have your JSP generate JSON directly instead of HTML. When the client sends a POST request to the server, the JSP processes it and returns pure JSON as the ajax response.

Answer ā„–2

It seems like the ideal scenario for implementing AJAX - you can send the request using JavaScript, and then handle the response with JavaScript as well. This way, the page doesn't need to refresh.

If you're utilizing jQuery, you can refer to this resource for a guide on how to set it up, which should be a relatively straightforward process: http://api.jquery.com/jQuery.post/

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

Tips for displaying indentations on Tube Geometry using THREE.js

Currently, I have a project where I am tasked with displaying dents on a pipeline in a 3D format. To create the pipeline, I utilized THREE.js's tube geometry which is illustrated below: <!DOCTYPE html> <html lang="en"> <head> ...

Using nextJS to establish a context within a Server Component and incorporating a new library

I attempted to incorporate Framer Motion into my project, but when I added it, an error occurred. The error message displayed was: TypeError: createContext only works in Client Components. Add the "use client" directive at the top of the file to use it. Fo ...

Having trouble retrieving the JSON output as a variable value in my JavaScript page using PHP

I need to achieve the following output format: var sampleTags = ['c++', 'scala']; This is my JavaScript function: <script> $(document).ready(function(){ $(function(){ var sampleTags; ...

Obtaining real-time stock information for the website

I am in the process of designing a dynamic homepage that will feature real-time stock charts and a screening function for various indicators. To achieve this, I will need access to live stock data from thousands of companies. It is crucial that this data i ...

"Upon returning from a child component, the React component's method 'this.state.myState'

In my React code, I have a Parent component called BookApplication and a child component called SearchBox. The SearchBox contains an input field that should pass the input back to the parent component for event handling. The data flow seems to be working c ...

What could be causing my dangerouslySetInnerHTML to show altered content?

I am working on a project using React and have encountered an issue with the code: const externalMarkup = ` <a data-refpt='DN_0OKF_177480_ID0EMPAC' /> <ol> <li value='1'> <p> <strong&g ...

What is the process for filtering records by a date greater than in the Material Table?

How can I filter the Material table by date values greater than the current value? I've been able to filter by exact date so far, but I need to filter all values that are greater than or equal to the current value in the table. <TableMaterial ...

The file selection feature in the browser is malfunctioning when attempting to upload files using either JQuery or JavaScript

I am experiencing an issue where the file select explorer closes after three clicks using jQuery. Below is my code: header.html: $(document).on('click', '.browse', function(){ var file = $(this).parent().parent().parent().find(&ap ...

pass the table ID to the controller using AngularJS

Curious about how to pass the selected row's id from a table to the controller when displaying its details? Take a look at this code snippet: app.js: .controller("etudmodifCtrl", ["$scope", "$http", "filterFilter", "$rootScope", "logger", "$filter", ...

Combining arrays of objects: a step-by-step guide

We start with an array A and an array B: let arrA = [{ name: 'twitter', active: true }, { name: 'medium', active: false }, { name: 'platinum', active: false } ]; Arra ...

Alert: Route.get() is requesting a callback function, but is receiving an [object Undefined] while attempting multiple exports

I'm attempting to export the middleware function so that it can be called by other classes. I tried searching on Google, but couldn't find a solution that worked for my situation. Below is the code snippet: auth.js isLoggedIn = (req, res, nex ...

What is the best way to send a prop from a parent component to its child using context in React?

Currently, I am working on fetching data in a React application. My goal is to extract an individual value from the response and pass it as a prop in a context from a parent component. The `trendingData` variable holds information retrieved from an API cal ...

Numerous AJAX requests consolidated into a single file

Here is my HTML code snippet: <div class="a1"></div> <div class="a2"></div> <div class="a3"></div> <div class="a4"></div> <div class="a5"></div> I am looking to make an AJAX request in the follo ...

What is the best way to retrieve a state variable within the getServerSideProps() function in NextJS?

Introduction Greetings everyone, I am a newcomer to NextJS. Currently, I am in the process of developing a weather application that utilizes external APIs. My main task involves fetching data from an API and displaying it on the frontend. Desired Function ...

Is it feasible to implement automatic window closure on the alternate website?

Imagine I have a website, let's say http://myownsite.com, and my desire is to execute a script that will open a new window on Safari or any other browser for a site which I do not own: http://theothersite.com If I lack control over that specific site ...

Automatically Populate Text Field with the URL of the Current Page

I am hoping to automatically fill a hidden text field with the URL of the current page so that I can keep track of where form submissions are coming from. This simple solution will help me streamline my inquiry responses and save time. To clarify, upon lo ...

When the checkbox is selected and clicked, the relevant information will not be shown using jQuery AJAX

I am in the process of developing an online store. When I select a category using a checkbox, the relevant products should be displayed. However, the results are showing up as undefined. I have included what I have tried so far below. For example, if I cho ...

Enhance communication system by optimizing MySQL, JavaScript, and PHP chat functionality

I have created a chat application using Javascript, PHP, and MySQL for two users. Every 3 seconds, it makes an AJAX request to a PHP file to retrieve messages from the database and update the page. Currently, the PHP query used is: SELECT * FROM tmessages ...

What resources are available for json schema implementation in Qt, C++, and C programming languages?

Qt's robust support for XML includes schema validation capabilities. While Qt also offers support for JSON, it seems to be not as comprehensive. It's unclear whether Qt supports json-schema or any form of JSON schema validation. Is there a reli ...

Tips on causing JavaScript execution to halt until an element has finished rendering

test.view.js timeDBox = new sap.ui.commons.DropdownBox({layoutData: new sap.ui.layout.GridData({linebreak: true}), change: function(oEvent){ oController.getKeyEqChart(); }, }), new sap ...