Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it
    Registrato dal
    Jun 2009
    Messaggi
    19

    [JSP]che tipo di errore è?

    ciao a tutti
    ho fatto la seguente pagina jsp che fa da interfaccia con una servlet:
    codice:
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    
    <%@page import="it.netmon.OutputBean"%><html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
    
    <form method="post" name="myForm" action="/NetMon/AdminServlet">
    
    	<table>
    		<tr>
    			<td>Tipo Richiesta</td>
    			<td>
    				<select name="opRich">
    					<option value="1" <%=request.getParameter("opRich").equals("1")?"selected":"" %>>Lista Client[1]</option>
    					<option value="2" <%=request.getParameter("opRich").equals("2")?"selected":"" %>>Info pc [2]</option>
    					<option value="3" <%=request.getParameter("opRich").equals("3")?"selected":"" %>>Test TCP [3]</option>
    					<option value="4" <%=request.getParameter("opRich").equals("4")?"selected":"" %>>Test UDP [4]</option>
    					<option value="5" <%=request.getParameter("opRich").equals("5")?"selected":"" %>>Carico Centralizzato [5]</option>
    					<option value="6" <%=request.getParameter("opRich").equals("6")?"selected":"" %>>Carico anello[6]</option>
    					<option value="7" <%=request.getParameter("opRich").equals("7")?"selected":"" %>>Carico anello server[7]</option>	
    				</select>
    			</td>
    		</tr>
    		<tr>
    			<td><input type="submit" name="Invio" value="Invio" /></td>
    			<td><input type="submit" onclick="document.myForm.action='/NetMon/index.jsp'"  name="Reset" value="Reset"/></td>
    		</tr>
    	</table>
    </form>
    <% 	
    	if (request.getParameter("Reset") != null) {
    		session.setAttribute("outputBean",null);
    	}
    	
    	if (request.getSession().getAttribute("outputBean") != null) {
    		OutputBean ob = (OutputBean)request.getSession().getAttribute("outputBean");
    		if (request.getParameter("opRich").equals("1")) {/* stampa solo le opzioni 1*/}
    		for(int a = 0;a < ob.getNomeClient().size();a++) { %>
    			Nome Client: <%= ob.getNomeClient().elementAt(a)%> attraverso la porta: <%= ob.getPortClient().elementAt(a)%>
    <%		}	%>
    		
    
    <%		if (ob.getNote() != null) {%>
    			Si è verificato un'errore: <%= ob.getNote()%>
    	<%	}
    	}
    
    %>
    
    </body>
    </html>
    ma quando la eseguo mi da il seguente errore:

    type Exception report

    message

    description The server encountered an internal error () that prevented it from fulfilling this request.

    exception

    org.apache.jasper.JasperException: java.lang.NullPointerException
    org.apache.jasper.servlet.JspServletWrapper.handle JspException(JspServletWrapper.java:491)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:419)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:717)


    root cause

    java.lang.NullPointerException
    org.apache.jsp.index_jsp._jspService(index_jsp.jav a:72)
    org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
    org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:377)
    org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:313)
    org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:260)
    javax.servlet.http.HttpServlet.service(HttpServlet .java:717)



    non riesco a capire a cosa sia dovuto...voi avete in mente qualcosa??

  2. #2
    Utente di HTML.it L'avatar di andbin
    Registrato dal
    Jan 2006
    residenza
    Italy
    Messaggi
    18,284

    Re: [JSP]che tipo di errore è?

    Originariamente inviato da seibi
    non riesco a capire a cosa sia dovuto...voi avete in mente qualcosa??
    La prima cosa che posso notare sono i vari test del tipo:

    request.getParameter("opRich").equals("1")

    Quando arrivi alla pagina per la prima volta, c'è da presumere che il parametro opRich non ci sia ancora, pertanto getParameter restituisce null e quindi invocare equals() su un null .... NullPointerException.

    Basta "girare" il test:

    "1".equals(request.getParameter("opRich"))
    Andrea, andbin.devSenior Java developerSCJP 5 (91%) • SCWCD 5 (94%)
    java.util.function Interfaces Cheat SheetJava Versions Cheat Sheet

  3. #3
    Utente di HTML.it
    Registrato dal
    Jun 2009
    Messaggi
    19
    grazie mille per la risposta...era proprio cosi

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.