Ho creato una pagina di errore in jsp ma ho due domande:
1.C’è modo di andare a capo come nella pagina di cortesia prodotte in automatico dal server?
Ecco lo schifo che leggo io:
java.lang.NullPointerException at org.apache.jsp.error_jsp._jspService(error_jsp.java:165) at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:458) at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386) at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330) at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:668) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:770) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.base/java.lang.Thread.run(Thread.java:844)
Gli ‘a capo’ sono andati a farsi friggere!
Qui il codice della pagina:
<%
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
response.setHeader("Expires", "0"); // Proxies.
%>
<%-- Con queste direttive non e' piu' necessario usare i codici HTML per scrivere i caratteri speciali. --%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="it">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="description" content="Applicazione web per la gestione di coordinate spaziotemporali">
<meta name="keywords" content="HTML,CSS,Java,Maven,JavaScript">
<meta name="author" content="Nome Cognome">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Esercitazione 1</title>
<!-- Librerie JS & CSS -->
<!-- assenti... -->
<!-- CSS -->
<link rel="stylesheet" type="text/css" href="/css/tema.css">
<!-- JS -->
<script src="/js/client_code.js"></script>
</head>
<body>
<h1>Errore</h1>
<div>
<img src="/immagini/errore.jpg" alt="Errore" class="imgResponsive">
<p>Siamo spiacenti, si è verificato un errore durante l'esecuzione:</p>
<p>
<%@ page isErrorPage="true"%>
<%@ page import="java.io.StringWriter" %>
<%@ page import="java.io.PrintWriter" %>
<i>Messaggio:</i><br><br>
<strong class="rosso-porpora"><%=exception.getMessage()%></strong>
<br><br><i>StackTrace:</i><br><br>
<%
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
exception.printStackTrace(printWriter);
out.println(stringWriter);
printWriter.close();
stringWriter.close();
%>
</p>
<p>Puoi ricollegarti alla home del sito <a href="/index.jsp">premendo qui</a>.</p>
</div>
<%@ include file="/copyright.jsp" %>
</body>
</html>
2.Nelle servlet al posto di:
Cosa dovrei scrivere nelle servlet al posto del codice seguente?
<%@ page errorPage=”error.jsp” %>