Combining Angular JS with JSP and Servelet

I have recently started learning Angular JS and I am attempting to combine it with JSP & Servlet. My goal is to create a simple code that retrieves data from an Action Class and displays it on the Index.jsp page. Below is my code:

Index.jsp -

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Fetch Data</title>
<script type="text/javascript" src="js/angular.min.js"></script>
<script>
 var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope , $http ) {


  $scope.getDataFromServer = function() {
    alert("Check Function");
    $http({
        method : 'GET',
        url : '/AngularJsServlet'
}).success(function(data, status, headers, config) {
    alert('data----'+data);   
    $scope.person = data;
  }).error(function(data, status, headers, config) {
    alert("failure");
   });
   };
  });
</script>
</head>
<body>
<div data-ng-app="myApp" data-ng-controller="myCtrl">

 <button data-ng-click="getDataFromServer()">Fetch data from server
            </button>
             <p>First Name : {{person.firstName}}</p>
       <p>Last Name : {{person.lastName}}</p>
 </div>
  </body>
</html>

PersonData.Java (Model Class) -

package com.model;

 public class PersonData {

 private String firstName;
 private String lastName;

 public String getFirstName() {
         return firstName;
 }

 public void setFirstName(String firstName) {
         this.firstName = firstName;
 }

 public String getLastName() {
         return lastName;
 }

 public void setLastName(String lastName) {
         this.lastName = lastName;
 }

 }

Answer №1

The issue is quite obvious. The 404 error indicates that the page you are trying to access is not found. Please double check your URL format, which should follow this pattern:

protocol://host:port/appName/page

It appears that you have overlooked including the appName in your URL. If the display name in your web.xml matches your project name, you can correct it by doing the following:

GET http://localhost:8080/Practice/AngularJsServlet

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

What causes the while loop in a threejs render function to not refresh each frame?

I'm struggling with handling an array of 8 cubes, each only 1 pixel tall. When a button is pressed, I want them to smoothly animate to a new height using a while loop. Here's my current implementation: if (buttonPressed) { console.log(' ...

JSON data localization

I am currently in the process of developing a hybrid mobile application with PhoneGap as the platform. My goal is to localize the app's data so that it can be accessed offline. Essentially, I want all JSON data received from the API to be stored local ...

The nth-child selector fails to function properly with a customized MUI component in CSS

I've created a styled component as shown below: const FormBox = styled(Box)(({ theme }) => ({ width: "47vw", height: "25vh", backgroundColor: theme.palette.grey[100], borderRadius: theme.shape.borderRadius, marginLeft: ...

How can the issue of the background fill option covering multiple loading bars be resolved?

I am currently relying on Google Translator, so there may be errors in the translation. The issue I am facing is that when I add a parameter with the "fillColor: '#f4f5f9'", the wheel covers one of the elements of Multiple Bars. I have modified ...

React component fails to re-render after state change

For the past two days, I've been struggling with this error and can't seem to fix it! I'm currently working on creating a weather app in React which utilizes the API. The app features a Bootstrap Navbar with a search option that allows user ...

Bird's-eye view captured by a high-angle camera

As I rotate a sphere around the z-axis, I'm looking for a way to prevent the camera from causing motion sickness by creating a stable elevated view of the sphere. How can I achieve this without the camera's movements being so jarring? If you&apo ...

Matrix filled with elements either being 1 or 0

I am in the process of developing a program that generates a random maze comprised of '1's and '0's. The maze does not necessarily have to be solvable. The main functionality of my program is to search through this maze and determine if ...

React: Modifying a single input field out of many

Can someone please review this code snippet: https://stackblitz.com/edit/react-koqfzp?file=src/Section.js Whenever I add an item, a random number is also added that I want to be able to edit. This number is displayed in a Material UI Text Field component. ...

How can we assign priority to the child element for detection by the "mouseover" event in jQuery?

Can you help me figure out how to make the "mouseover" event prioritize detecting the child element over its parent? This is the jQuery code I've been using: <script> $(function() { $("li").mouseover(function(event){ $('#log&a ...

Update the shared ArrayList for activities to be stored in the SharedPreferences

In my coding journey, I encountered a challenge involving an ArrayList<String> that I stored in shared preferences within the realm of Activity A. This list needed to be accessed from another activity called ListActivity. The process involved startin ...

The React Testing Library encountered an error: TypeError - actImplementation function not found

Encountering a TypeError: actImplementation is not a function error while testing out this component import React from 'react'; import { StyledHeaderContainer, StyledTitle } from './styled'; export const Header = () => { return ( ...

How to use jQuery to select an element by using 'this' on a button

I have a total of 5 divs, each containing 5 different texts. <div class="text"> <%= theComment.text %> </div> I am working with node.js, MongoDB, and Mongoose. In addition to the divs, I also have a button labeled EDIT with a cl ...

Adjust image size dynamically while keeping the original aspect ratio

Is there a way to scale variable portrait and landscape images dynamically to fit proportionally within a browser window? You can find my current image resizing attempt here: http://jsfiddle.net/6pnCH/4/ I would like the image to be already scaled vertic ...

Transferring data using a JavaScript enhanced form

I'm currently working on a search page that showcases results in a table format. I am looking to enhance the functionality using Javascript. The table is contained within a form, and each row offers multiple actions, such as adding a comment. While I ...

The customized sweet alert button is failing to trigger its designated function

I integrated vue-swal to show a pop-up dialog with customized functionality. However, I faced an issue while modifying the swal. In my modified version, there are 3 buttons each with specific actions that should be triggered upon clicking. But for some rea ...

Extremely sluggish change identification in combination Angular application

We are encountering consistent issues with slow change detection in our hybrid AngularJS / Angular 8 app, especially when dealing with components from different versions of the framework. The problem seems to arise when using older AngularJS components wit ...

Configuring table dimensions and layout in Word documents with Apache POI library in Java

My goal is to create a word document containing a table on a single page with 5 rows and 2 columns. The page size is set to 8.5" x 11" and I have specified the margins in the program. Below is the code snippet that I am using: XWPFDocument xWPFDocumen ...

Guide: Looping through a typed Viewbag array - best practices

I have passed a List<AdminUsers> through the Viewbag to a view. This list is then assigned to a JavaScript variable and looped through. However, when debugging on the view, I noticed that the for loop is not being executed, even though I set a break ...

The Node.js azure-storage TableService does not offer any functionalities or operations

Having trouble connecting to my Azure storage account due to issues with the azure-storage module. Specifically, after creating a TableService object, I am only able to access the filter method on it. When attempting to use methods like queryTables and cre ...

Is it possible to establish a standard view for the date/time input field, disregarding the user's

When working with a Django Form, I am incorporating a datepicker. While the solution may involve JS and HTML, my query remains specific. date_field= forms.DateField( input_formats=['%Y-%m-%d'], widget=forms.DateInput( format=& ...