i'm tryng to head out this problem but i can't figure it out. So i have my Servlet and my jsp page, but when i run the server and i click on the link that should trigger the logic for my jsp, just nothing happen. Here is my code:
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/JSP_Servlet/Servlet.java to edit this template
*/
package it.unica.fSociety.Servlet;
import it.unica.fSociety.Model.Videogioco;
import it.unica.fSociety.Model.VideogiocoFactory;
import java.io.IOException;
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;
import javax.servlet.http.HttpSession;
/**
*
* @author stefa
*/
@WebServlet(name = "VideogiochiServlet", urlPatterns = {"/listinoVideogiochi"})
public class VideogiochiServlet extends HttpServlet {
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
* methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
List<Videogioco> videogiochi = VideogiocoFactory.getInstance().getAllVideogiochi();
request.setAttribute("listinoVideogiochi", videogiochi);
request.getRequestDispatcher("listinoVideogiochi.jsp").forward(request,response);
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Handles the HTTP <code>POST</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Returns a short description of the servlet.
*
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}
The Servlet
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package it.unica.fSociety.Model;
import it.unica.fSociety.Database.DatabaseManager;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author stefa
*/
public class VideogiocoFactory {
private static VideogiocoFactory instance;
private VideogiocoFactory(){}
public static VideogiocoFactory getInstance(){
if(instance== null)
instance= new VideogiocoFactory();
return instance;
}
public List<Videogioco> getAllVideogiochi() {
Connection conn = null;
PreparedStatement stmt = null;
ResultSet set = null;
List<Videogioco> videogiochi = new ArrayList<>();
try {
conn = DatabaseManager.getInstance().gedDbConnection();
String query = "select * from videogioco";
stmt = conn.prepareStatement(query);
set = stmt.executeQuery();
while (set.next()) {
Videogioco videogioco = new Videogioco();
videogiochi.add(videogioco);
}
return videogiochi;
} catch (SQLException e) {
Logger.getLogger(VideogiocoFactory.class.getName()).log(Level.SEVERE, null, e);
} finally {
try {set.close(); } catch (Exception e) {}
try {stmt.close(); } catch (Exception e) {}
try {conn.close(); } catch (Exception e) {}
}
return null;
}
}
<!DOCTYPE html>
<html>
<head>
<title> GameSociety </title>
<meta charset="UTF-8">
<meta name ="author" content ="fSociety">
<meta name =" description " content =" Negozio online di videogiochi">
<meta name =" keywords" content ="videogiochi,pc,games">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="preconnect" href="https://fonts.googleapis.com/" >
<link rel="preconnect" href="https://fonts.gstatic.com/" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Mukta:wght@200&display=swap" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="style.css" media="screen"/>
</head>
<c:set var="page" value="index" scope="request"/>
<c:if test="${empty utente.getUsername()}">
<c:redirect url="login.jsp"/>
</c:if>
<c:if test="${not empty utente.getUsername()}">
<c:set var="page" value="listinoVideogiochi" scope="request"/>
</c:if>
<body>
<%@ include file="header.jsp" %>
<nav>
<div>
<ul>
<li><a href="index.jsp" > Home </a></li>
<li><a href ="nuovoProdotto.jsp"> Nuovo Videogame </a></li>
<li><a href ="listinoVideogiochi.jsp" class="active"> Listino Videogiochi </a></li>
<li><a href ="chiSiamo.jsp"> Chi siamo </a></li>
<li><a href ="login.jsp"> Login </a></li>
</ul>
</div>
</nav>
<br>
<div class="col-3 col-s-3">
<%@ include file="pubblicità1.jsp" %>
<div id="bookmark1" class="presentazioneListino">
Acquista i tuoi giochi preferiti, o trovane di nuovi,comodamente
da casa e scaricali subito!
Qui troverai tutti i videogiochi in vendita nel nostro sito. <br>
Scegli tra quelli più ricercati dagli utenti. Solo il
meglio del mondo games scelto per voi dallo staff di GameSociety.
<br> Inizia a fare acquisti!
</div>
<br>
<h2 id="titoloh2">Tutti i titoli</h2>
<article>
<div class="boxListino">
<c:forEach items="${listinoVideogiochi}" var="videogiochi">
<h3 class="titoloListino"> "${videogiochi.getTitolo()}"</h3>
<img title ="BlackMesa" alt="Foto del gioco di Black Mesa" src="${videogiochi.getUrl_Foto(
<div class="infoGioco">
<b>Genere:</b> <i> "${videogiochi.getGenere()}"</i>
<br>
<b>Trama:</b> Sei Gordon Freeman, un fisico teorico del Black Mesa
Research Facility. Quando un esperimento di routine va
terribilmente storto, ti ritrovi a combattere un'invasione
aliena interdimenzionale. Riuscirai a salvare la tua squadra
scientifica e il mondo??
<br>
<b>Prezzo:</b> 14,99€
<br>
<b>Produttore:</b> Crowbar Collective.
<br>
<b>Data di Rilascio:</b> 6 Marzo 2020.
</div>
<h4 class="titoloh4">Requisiti di Sistema:</h4>
<div class="tabella">
<table>
<tr>
<th></th>
<th>Minimi:</th>
<th>Consigliati:</th>
</tr>
<tr>
<td><b>Sistema operativo:</b></td>
<td><i>Windows 7(32/64-bit)/Vista or Greater.</i></td>
<td><i>Windows 7(32/64-bit) or Greater.</i></td>
</tr>
<tr>
<td><b>Processore: </b></td>
<td><i>2.6 Dual Core Processor or Greater.</i></td>
<td><i>3.2 Quad Core Processor or Greater.</i></td>
</tr>
<tr>
<td><b>Memoria: </b></td>
<td><i>6 GB di RAM.</i></td>
<td><i>8 GB di RAM.</i></td>
</tr>
<tr>
<td><b>Scheda Video: </b></td>
<td><i>2 GB Dedicated Video Card or Greater.</i></td>
<td><i>4 GB Dedicated Video Card or Greater.</i></td>
</tr>
</table>
</div>
<div class="votoGioco">
<i>Ti è piaciuto questo gioco?</i>
<button type ="submit">
<img alt="sì" src="img/si.png" width="14" height="14" /> Sì!
</button>
<button type ="submit">
<img alt="no" src="img/no.png" width="14" height="14" /> No!
</button>
</div>
</div>
</c:forEach>
</article>
</article>
<a href ="#bookmark1"> <b>Torna su!</b></a>
</div>
<%@ include file="pubblicità2.jsp" %>
<%@ include file="footer.jsp" %>
</body>
</html>
the jsp
Thanks everyone for the support