Employing JavaScript to transfer a string to a Servlet, and then returning the results from the Servlet back to JavaScript

Firstly, I apologize for any errors in my grammar. English is not my first language, but I will do my best to explain my issue clearly.

I am currently developing a web application where users can input a link. (Question 1) This link needs to be sent to a server/servlet for processing. (Question 2) Once the processing is complete, the servlet will send back a JSON array to the JavaScript component of my application.

I am completely new to this type of development, and it is crucial for me to understand how it all works and how to make it work. While it may seem simple, I have spent several weeks trying to figure it out without success.

The application utilizes SAP UI5 libraries (Question 3), and I am also curious if there is a way to parse JSON using these UI5 libraries.

I hope that I have outlined my problem clearly enough to receive assistance. Thank you in advance for any help offered!

Answer №1

To transmit the string to the server/servlet, you can use ajax in either POST or GET form. The choice is yours.

I suggest incorporating a JavaScript plugin such as jQuery (JQuery Ajax API) because regular ajax code can be messy (W3Schools Ajax).

When it comes to the servlet/server communicating back to the client, the process is straightforward by writing to the page. In a typical servlet scenario, it might look something like this:

out.print("This is a message");

In summary: Imagine test.jsp as your servlet. You aim to send "Hi" from the client (browser) via GET to the servlet and have the servlet respond with "Hello."

You could initiate an ajax request of type GET to the URL "test.jsp?param=Hi." Upon receiving this page request, the servlet processes it, discards the unused parameter, and outputs "Hello" to the page.

The ajax call will yield "Hello" on the client side, allowing you to manipulate it further without refreshing or navigating away from the original document where the JavaScript was executed.

Alternatively, consider utilizing websockets which employ sockets in JavaScript for data transmission.

Do explore this similar question: How to send a string to a servlet from javascript using xmlhttprequest

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

employing requirejs for fetching npm modules

I need help running this code in HTML. Can someone show me how to use require.js for this? const monerojs = require("monero-javascript"); I tried the following but it doesn't work, I keep getting a "Script error for "monero-javascript"". requirejs([ ...

Triggering the function once the text field is tapped again

I recently integrated a JavaScript scroll framework to create a stylish scrollbar for windows. I simply added it to a div: this.displayDiv = function () { $("#myDiv").niceScroll(); } <a href="#" onclick="manager.displayDiv();"> It ...

Analyzing HTML tags with Apache Tika

Is there a way to retrieve the value of this <DIV> with the ID 48227783 using Apache TIKA? <div class="postcolor post_text" data-postid="48227783">Ownage!<br /></div> I have attempted to fetch the value 'Ownage!', I have ...

What is the best way to identify the clicked cell?

I'm a JavaScript newbie trying to work with ExtJS 3.4. I've set up a basic tree with 3 columns and now I want to figure out which cell, row, or column has been selected. Currently, I'm following the example provided by Sencha at : var tr ...

Managing multiple sets of radio button groups in a React applicationHere are some tips on navigating through multiple sets of

I'm seeking some assistance or suggestions on how to make this work - I have multiple sets of radio buttons grouped together. The issue I'm facing is that when I select one group, it shows the correct input, but if I then check another group, the ...

Is my configuration file causing Express to serve up index.html instead of my Webpack bundle?

My website is having trouble loading because instead of the bundle.js file, it's returning the index.html file. This project was originally created a few years ago and worked without any issues. However, I'm currently trying to revive it and enc ...

Is there a way to retrieve the Response object in Express from outside the Route

Currently, my backend API is built using Express JS. Instead of using the res object directly in the route controller, I am looking to access it from a custom service. While I know that I can simply pass res as an argument to the service function and use ...

Updating the object in router.get and res.render in Node.js and Express after loading

When loading the page, I encounter an error with req.body.firstname.length inside router.use. The error states: TypeError: Cannot read property 'length' of undefined The issue arises because the default value is undefined for the input form. ...

Angular 4's Panel Window: A User-Friendly Interface

Having experience with Adobe Flex, I am familiar with creating new panel windows in Action Script by using the 'new' keyword and popping them up using popups. The customization of these windows was achieved through functions provided in the Panel ...

The onRendered function fails to load all data in the template

I'm dealing with a frustrating bug that I just can't seem to fix. I've been attempting to load all users using Users.find() into one of my layout sub-templates, but for some reason, it's not working as expected. Instead of loading all u ...

Choosing from various criteria in JQ when one is a partial match

In my search, I have found many responses that are similar to what I need, but not quite there. I am working on parsing a JSON file using the following command: cat file.json | jq -r ".[] | select(.name == \"${VALUE}\" or .guid == ...

How can I place a THREE.ArrowHelper on a specific layer in Three.js?

Exploring the world of Three.js, I'm striving to understand how to organize elements onto separate layers. One of the challenges I'm facing involves an ArrowHelper that I've set up and added to the scene in the following manner: var ar ...

Learn how to create a button that will only submit a value when clicked using Node.js and EJS

Currently in my ejs file, I have a button that sends a value to app.js instantly when the program runs. However, I want it to only submit the value when clicked by the user. <% notesArray.forEach((note,i) =>{ %> <div class="note"> ...

Value assigned to each iteration in the Json data loop updates the existing data

There is an array that receives a Json variable as a parameter. Within the loop, additional sub-variables are added to the Json variable, each with new values assigned during each iteration. var getDataArrList = function (arrList, itemData, forControlMode ...

Issue with Stack Overflow encountered in LibGDX while utilizing the methods "this.create()" and "this.render()"

I encountered an issue while following an online tutorial on creating a space shooter game using LibGDX and IntelliJ IDEA. Everything was going smoothly until I added the "this.create()" and "this.render()" functions. As soon as these functions were includ ...

Extracting internal objects from JSON using JAXB

When attempting to unmarshall input JSON into JAXB objects using Eclipselink, I encounter an issue where nested objects are set as null. Even when trying to unmarshall the nested object by itself, it still ends up null when further nested objects are invol ...

Attempting to Retrieve Information from a Get Request using Axios

I am attempting to retrieve SQL data from a GET request using axios. My backend is set up with an express server, and the front end is built with React. In my React component, I have a function that contains the axios GET call, which I then invoke within t ...

Navigating the complexities of extracting and storing a data type from a collection of objects

Dealing with a messy API that returns inconsistent values is quite challenging. Instead of manually creating types for each entry, I am looking for a way to infer the types programmatically. One approach could be by analyzing an array like this: const arr ...

Troubleshooting: The issue with applying 'style' in react-draft-wysiwyg

Is there a way to style my textboxes within a rectangle with a default height? I attempted to use the style attribute in my <Editor /> but it didn't work. import { Editor } from "react-draft-wysiwyg"; import { EditorState } from " ...

How can I connect with a locally hosted RESTful Web Service created using NetBeans IDE from an Android device?

I recently discovered that the NetBeans IDE can effortlessly generate RESTful Web Services from a database, where the table is packed into an entity class. Following a helpful tutorial, I successfully generated the RESTful Web Service. Now comes the part ...