The backend is not receiving the variable through RESTful communication

I'm attempting to pass the word "hello" to the backend of my code using the URL. However, instead of sending the string "hello" to my Java backend code, it's sending an empty string.

Below is my backend code:

@GET
@Path("getJob/{stepName}")
@Produces(MediaType.APPLICATION_JSON)
public List<Step> getStepByName(@PathParam("stepName") String stepName) {
    String x = stepName;
    System.out.println(x);
    return null;

            //List<ModuleProcCount> pusher = statements.inMod(dbc,theReader);
            //for(ModuleProcCount p : pusher) {
            //  input.add(p.modName + " " + p.modCount);
            //}
            //  return result;


        }

And here is my JavaScript:

performanceApp.controller("homectrl", function($scope, $http){
    var x = "rest/performance/getJob/hellp";
    $http.get(x).then(function(response){

    }); 


});

I'm not sure what I'm doing wrong or what the issue is with this code, as it seems pretty straightforward.

Answer №1

Although I may not fully grasp all of your points, it seems like you are utilizing AngularJS. However, it appears that there may be an issue with the header of your request. To clarify this, consider modifying the header in your client-side JavaScript code to ensure that the server can properly interpret the type of media being received.

For guidance, you can refer to the AngularJs documentation, which provides a helpful example:

var req = {
 method: 'POST',
 url: 'http://example.com',
 headers: {
   'Content-Type': 'application/json'
 },
 data: { test: 'test' }
}

$http(req).then(function(){...}, function(){...});

I recommend examining the request within the network tab of your browser's devtool to ensure that the content-type is set as application/json.

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

Here is a way to return a 400 response in `express.js` when the JSON request body is invalid

How can I make my application send a response with status code 400 instead of throwing an error if the request body contains invalid JSON? import express from 'express' app.use(express.urlencoded({ extended: false })) app.use(express.json()) ...

Evolving the appearance of every vacant element

Currently, I am working on a project that allows users to add items. To facilitate this process, I have included an "add another" button which enables them to include additional items all at once. In order to validate the form and save values to the datab ...

What is the best way to generate a random string output from an object in JavaScript?

I'm struggling with extracting a random value from the object provided below, can anyone help me out? const hellos = { English: "Hello", Japanese: "Konnichiwa", German: "Hallo", Spanish: "Hola", Arabic: "Ah ...

Issue with JQuery time picker functionality not functioning properly upon repeat usage

I am facing an issue with a modal dialog that contains a form loaded via ajax. The form includes a time field populated using the jquery timepicker. Everything works perfectly when I open the dialog for the first time. However, if I try to load the dialog ...

We are hosting an event focused on DOM text selection outside of Input or TextArea elements

I need help finding a Javascript event that triggers when a user highlights paragraph text with their mouse on a web page. Once the text is highlighted, I want to access it using window.getSelection(). Just to clarify, I am not looking for ways to capture ...

Identifying and detecting Label IDs when clicked using the for tag

I am facing an issue with labels and input fields in my code. I have multiple labels that trigger the same input field, but I want to know which specific label triggered the input field. <label id="label1" for="input1">Document1</label> <la ...

Why is my event.target.value not updating correctly in React useState?

My problem is that when I use useState, I am receiving incorrect numbers For example, if I print e.target.value it might display 1, but my selectedIndex shows 2. Similarly, when I have a selectedIndex of 0, it retrieves something different like 1. Any tho ...

Node.js application - varying NODE_ENV upon NPM launch

Operating my node.js application can be quite confusing. When launched by npm start, it operates in "production" mode, whereas when launched using node start.js, it runs in 'development' mode. I want to ensure that the 'development' mo ...

How can I retrieve a text file using an API in a Next.js application?

Is there a way to download a text file using an API in Next.js? The console.log(ninjas) function is already displaying the correct information. I have tested the API with Postman and it works perfectly. When I use GET in Postman, the same information is ...

Obtain identical encryption results with CryptoJS (JavaScript) and OpenSSL (PHP)

I am in the process of integrating a PHP encryption function into a ReactJS application. I have a requirement to transmit the token in a specific format that was generated using the OpenSSL library function (openssl_encrypt). It has been observed that the ...

Issue in Eclipse regarding Selenium automation error

I'm encountering difficulties getting this code to function. Just a heads up, I am very new to this. package mypackage; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class myclass { public static ...

A guide on emphasizing the chosen row in AngularJS

When transitioning from the 'home page' to the 'details page' in AngularJS, I want the selected row in the table to be highlighted. I attempted to achieve this with the code below, but it is not functioning as intended. Code snippet fo ...

Update the content within a document and implement jQuery to make it clickable

Within my webpage, there is a random occurrence of the word -FORM-. I am looking to replace this word with another text that includes dashes for creating a clickable div. Despite having some code that successfully replaces the text, it lacks the function ...

Vue.js - Axios Get request received an object response

My current project is built on Vue.js and I am using Flask for the API. The issue arises when trying to make an axios.get request - the API returns an object 'Object'. Interestingly, when testing the same request in Postman, it works fine and ret ...

Mirage blocking Ember.js ajax POST request from going through

Currently, I am in the process of writing tests for a component within my Ember application. This particular component is responsible for executing an ajax POST request to communicate with my servers API and retrieve a file location string as a response. ...

Issue with highlighting when one string overlaps with another

I am facing a challenge with handling a string that contains Lorem Ipsum text. I have JSON data that specifies the start and end offsets of certain sections within the text that I need to highlight. The approach I am currently using involves sorting the JS ...

What is the proper way to use an AND operation in jQuery on multiple attributes?

I have a list of DIV tags structured as follows: <div status="1" searchText="some text">...</div> <div status="2" searchText="more text">...</div> <div status="1" searchText="even">...</div> To toggle the visibility of ...

I seem to be facing some issues with SkipException in testNG. Can anyone provide guidance on what might be

As a newcomer to selenium UI automation, I am currently experimenting with a simple application using Java and TestNG. My goal is to integrate this test with Continuous Integration (CI), but the test environment URL will vary with each deployment. The ke ...

Finding a character that appears either once or thrice

In my work on JavaScript regex for markdown formatting, I am trying to match instances where a single underscore (_) or asterisk (*) occurs once (at the beginning, end, or surrounded by other characters or whitespace), as well as occurrences of three under ...

Ignore one specific file when importing all files in Angular 7

In my Angular 7 project, I am utilizing C3 and importing all the necessary files at the beginning of my .ts component file using a wildcard. import * as c3 from 'c3'; While this method works well overall, I encountered an issue where my CSS ove ...