I want to display an autor first name and last name using Java beans in my Java EE web application but for some reasons i ignore, nothing show up in my index.jsp web page when i write <p>Bonjour ${ auteur.prenom } ${ auteur.nom }</p>
(Only Bonjour and then nothing). I made sure everything in web.xml was fine but i really can't find the reason of my little problem. I thought maybe something is wrong with the path in this line
this.getServletContext().getRequestDispatcher("/index.jsp").forward(request, response);
thank you.
index.jsp
<%--
Created by IntelliJ IDEA.
User: vorolf
Date: 2020-09-10
Time: 4:49 p.m.
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
<title>Title</title>
</head>
<body>
Hello, World!
<a href="myServlet">Appuyez ici pour avoir l’heure</a>
<br>
<p>Bonjour ${ auteur.prenom } ${ auteur.nom }</p>
<p>${ auteur.actif ? 'Vous êtes très actif !' : 'Vous êtes inactif !' }</p>
</body>
</html>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<display-name>my app</display-name>
<description>
description test
</description>
<servlet>
<servlet-name>myServlet</servlet-name>
<servlet-class>myServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>Test</servlet-name>
<servlet-class>Test</servlet-class>
</servlet>
<!--mapping-->
<servlet-mapping>
<servlet-name>Test</servlet-name>
<url-pattern>/Test</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>myServlet</servlet-name>
<url-pattern>/myServlet</url-pattern>
</servlet-mapping>
</web-app>
Test.java servlet
import beans.Auteur;
import java.io.IOException;
import java.io.PrintWriter;
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;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Auteur auteur = new Auteur();
auteur.setPrenom("Mathieu");
auteur.setNom("Nebra");
auteur.setActif(true);
request.setAttribute("auteur", auteur);
this.getServletContext().getRequestDispatcher("/index.jsp").forward(request, response);
}
}
my bean
package beans;
import java.io.Serializable;
public class Auteur implements Serializable {
private String nom;
private String prenom;
private boolean actif;
public Auteur(){
}
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
public String getPrenom() {
return prenom;
}
public void setPrenom(String prenom) {
this.prenom = prenom;
}
public boolean isActif() {
return actif;
}
public void setActif(boolean actif) {
this.actif = actif;
}
}
My project structure
The URL of my website http://localhost:8080/demo/
and the generated output of the web page is
<html>
<head>
<title>Title</title>
</head>
<body>
Hello, World!
<a href="myServlet">Appuyez ici pour avoir l’heure</a>
<br>
<p>Bonjour </p>
<p>Vous êtes inactif !</p>
</body>
</html>