[Débutant] httpservletrequest erreur Err java.lang.NullPointerException
Bonjour à tous,
Je débute en ce qui concerne les httpservletrequest, je voudrais juste apprendre à récupérer un paramètre donc grâce a un exemple trouvé sur internet j'ai réalisé le code suivant :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| public final class adeline extends HttpServlet
{
static PrintWriter writer = null;
public static void outr(String instr, boolean nl) { // Envoi d'une chaine de caracteres suivi en option du tag '<br>'
writer.print(instr);
if (nl) writer.print("<br>");
}
public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<BODY BGCOLOR=\"#FDF5E6\">\n" + "<H1 ALIGN=CENTER></H1>\n" +"<TABLE BORDER=1 ALIGN=CENTER>\n" + "<TR BGCOLOR=\"#FFAD00\">\n" + "<TH>Parameter Name<TH>Parameter Value(s)");
Enumeration paramNames = request.getParameterNames();
while(paramNames.hasMoreElements()) {
String paramName = (String)paramNames.nextElement();
out.println("<TR><TD>" + paramName + "\n<TD>");
String[] paramValues = request.getParameterValues(paramName);
if (paramValues.length == 1) {
String paramValue = paramValues[0];
if (paramValue.length() == 0)
out.print("<I>No Value</I>");
else
out.print(paramValue);
} else {
out.println("<UL>");
for(int i=0; i<paramValues.length; i++) {
out.println("<LI>" + paramValues[i]);
}
out.println("</UL>");
}
}
out.println("</TABLE>\n</BODY></HTML>");
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
public static void equipe()
{
outr("<HTML><HEAD><TITLE>A Sample FORM using POST</TITLE></HEAD><BODY BGCOLOR=\"#FDF5E6\"><H1 ALIGN=\"CENTER\">A Sample FORM using POST</H1><FORM>Item Number:<INPUT TYPE=\"TEXT\" NAME=\"itemNum\"></TEXTAREA><BR><CENTER><INPUT TYPE=\"SUBMIT\" VALUE=\"Submit Order\"></CENTER></FORM></BODY></HTML>",false);
}
} |
mais voici mon erreur :
Err java.lang.NullPointerException
suis-je vraiment loin du compte?