I´m working in ionic app. When the user logs in, a file with different information is sent to the server.
let datos = this.getInfoLogin();
The content of the method is as follows
getInfoLogin(): any {
let datos = {
"version": this.versionNumber,
"user": this.loginGroup.value.user,
"fechaLogin": this.getCurrentDate(),
"password": this.loginGroup.value.password
};
return datos;
}
I send that code to the server with an angular post service
this.http.postLogin(datos).subscribe(respLogin => {});
http.service.ts
@Injectable({
providedIn: 'root'
})
export class HttpService {
private url = 'http://localhost:8085/nombreApp/LoginServlet';
// Http Headers
headers: HttpHeaders = new HttpHeaders({
Accept: "application/json",
"Content-Type": "application/json; charset='utf-8'",
});
constructor(public http: HttpClient) {
console.log("Servicio login listo");
}
postLogin(login): Observable<any> {
return this.http.post(`${this.url}`, login, { headers: this.headers });
}
}
But on the server I always get null when I use
String user = request.getParameter("user");
LoginServlet.java
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
response.setContentType("text/html");
String user = request.getParameter("user");
} catch (Exception e) {
LOGGER.log(Level.SEVERE, "Error PrintWriter." + e.getMessage());
}
}
I know the data arrives but I don't know how to read it. What am I doing wrong? I have searched a lot and I see that the correct way to do it is this. I'm right?