我有以下代码,问题是out.println(“Clave =”+ request.getParameter(“clave”)+“。”);写入null。 我一直在这个论坛上寻找解决方案,但我找不到任何东西。
HTML:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Registro de votante</title>
<link href="estilos.css" rel="stylesheet" type="text/css">
</head>
<body>
<form method="post" action="CreaVotante">
<div id="reg">
<table>
<tr>
<td colspan="2">
<h1>Regístrate para votar</h1>
</td>
</tr>
<tr>
<td>
<p>NIF</p>
</td>
<td>
<input type="text" name="nif">
</td>
</tr>
<tr>
<td>
<p>Clave</p>
</td>
<td>
<input type="text" name="clave">
</td>
</tr>
<tr>
<td>
</td>
<td>
<input type="submit" name="registro">
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
的Servlet
package Controlador;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
* @author Lux
*/
public class CreaVotante 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 {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
/* TODO output your page here. You may use following sample code. */
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet CreaVotante</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Nif= " +request.getParameter("nif")+ "</h1>");
out.println("<h1>Clave= " +request.getParameter("clave")+ "</h1>");
out.println("</body>");
out.println("</html>");
}
}
// <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);
}
}