mardi 26 novembre 2019

sending data from a servlet javaEE to an angular component

am a beginner in javaEE,I work with angular in FrontEnd and javaEE in BackEnd.I want to send data from a servlet to an angular component and I wanna know if is it possible what instruction i should include in my servlet,in this example i wanna send the list of users(utilisateurs) to angular component for treatment,here is my code of servlet. ps1: I use module HttpClient in angular. ps2: I don't use Spring framework.

Test.java

package com.coors.servlets;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.octest.beans.Utilisateur;
import com.octest.dao.DaoFactory;
import com.octest.dao.UtilisateurDao;
import com.octest.dao.UtilisateurDaoImpl;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/test")
public class Test extends HttpServlet {
private static final long serialVersionUID = 1L;
private UtilisateurDao utilisateurDao;
private DaoFactory daoFactory; 

public Test() {
    super();
}

@Override
public void init() throws ServletException {
    daoFactory=DaoFactory.getInstance();
    utilisateurDao=daoFactory.getUtilisateurDao();
}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    this.utilisateurDao.lister();//I  get the list of users

    //here what instruction ?????????????????????????????????????????
}

public void doPost( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
}

}




Aucun commentaire:

Enregistrer un commentaire