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

Assigning attributes to each letter in a pangram

I am attempting to assign the appropriate class to a group of elements, representing each letter in the alphabet. The elements have IDs ranging from #alpha_0 to #alpha_25. If a letter appears just once in the input, it should be displayed in green. If a le ...

When the form is submitted, any blank inputs and their corresponding hidden fields will be disabled

I created a form that has multiple input fields, and users have the option to enter values or leave them blank. Each input field is accompanied by a hidden input field which contains a specific id unique to the corresponding visible input field. To disable ...

The validations continue to function properly even when HTML has been removed

In my form, I have implemented an "addmore" functionality that allows users to dynamically add a set of HTML input fields. Users can also remove the added rows if needed. While everything is functioning correctly, I am encountering an issue where validatio ...

What is the best way to handle form data for JSON manipulation in jQuery?

var checkedValues = $('.required:checked').map(function () { return this.value; }).get(); var arr = new Array(10); alert(checkedValues); alert("number of values in it " +checkedValu ...

Incorporate a background image with the JavaScript CSS property

I'm having trouble adding a background image using the Javascript CSS property in my code. When I directly add the 'url', it works fine. Could the issue be with the 'weatherImage' variable? Javascript var OpenWeatherKey = ' ...

No content sent in the request body while implementing fetch

Attempting to send graphql calls from a React component to a PHP server using the fetch method for the first time. The setup involves React JS on the client-side and Symfony 4 on the server-side. Despite indications that data is being sent in the browser ...

I am encountering an issue where the msal-browser login process seems to be frozen at the callback

After successfully installing the msal-browser package, I am able to log in. However, I encounter an issue where the screen gets stuck at the callback URL with a code. The samples provided in the GitHub repository demonstrate returning an access token in ...

Is there a way to change a string that says "False" into a Boolean value representing false?

When retrieving values from the backend, I am receiving them as strings 'True' and 'False'. I have been attempting to convert these values into actual Boolean values, however, my current method always returns true. What is the correct a ...

``Identifying HTML elements dynamically on a webpage can be achieved by using various methods and

Within my application page, there is a dynamic web table that populates with multiple rows and columns based on the input data. In one particular column cell ("td"), the content may vary between a "p" tag or a "button" tag (appearing as a link) depending o ...

When navigating to a new route using history.push in React, it's important to ensure that the correct state is

My goal is to implement a smooth exiting animation with framer motion based on the user's current route and next destination. I specifically want the background to slide away only when transitioning from route A to route D. To achieve this, I decided ...

Issue with IE7 when using JQuery to repopulate a <ul> unordered list: new elements showing up under previously hidden elements

Within this javascript snippet, I am utilizing the code below to clear out a list of countries within a <ul> element and then repopulate it (with a slight animation using jQuery's hide() function). The functionality works smoothly in Chrome and ...

Managing "unprocessed information" in a Node.js environment and transferring the information through a Node Express endpoint

Currently, I am in the process of making an API call to retrieve a file using axios: async function fetchData() { const configuration = {}; // { responseType: 'stream'}; const { response } = await axios.get(URL, configuration); c ...

Different ways to call an ES6 class that is bundled in the <script> tag

Currently, I am utilizing Webpack to transpile my ES6 classes. Within the bundle, there is a Service class that can be imported by other bundled scripts. class Service { constructor() { // } someMethod(data) { // } } expo ...

An issue occurred with player.markers not being recognized as a function when trying to utilize videojs markers

I am trying to add markers to my videojs player timeline. I have successfully implemented this feature a few months ago in a different project, but now when I try to use it again, I am encountering errors in the console and unable to see the markers on the ...

Struggling to pass state values between React components

I'm having trouble passing the state of my functions through. I've included {state.name.user} and {onInputChange}, but I keep encountering errors. <Navigation isSignedIn={isSignedIn} onRouteChange={onRouteChange} /> { route === ...

Unexplainable space or padding issue detected in OwlCarousel grid gallery

There seems to be an unusual gap or margin at the bottom of each row section in this portfolio grid gallery that's running in OwlCarousel. You can view an example here. https://i.stack.imgur.com/NHOBd.png I've spent a lot of time trying to solv ...

Improve the parallax effect in your React component

Do you have any tips on smoothing out the scrolling animation for a React component with a simple parallax effect? I tried using requestAnimationFrame() in vanilla JS, but it doesn't seem to work well within the React component's rendering cycle. ...

Angular JS: keep controllers in sync when data changes in another controller

My Task: I am working on a simple HTML file that displays the first page. This page consists of a title and a button, with an initial setting of $scope.index = 0 to represent the first position of an array. Clicking on the next button takes us to the first ...

Tips for fixing View Encapsulation problem in Angular8

I have a parent component and a child component. The child component is created as a modal component. I have included the child component selector inside the parent component and set the view encapsulation to none so that it will inherit the parent compone ...

How can I pass the content of a pug input element to a JavaScript function?

Attempting to manipulate data on a database using HTML buttons and encountering an issue when trying to insert data. The setup involves a Pug page called by Node Express, which generally functions well until the insertion process. Here is a snippet from th ...