我創建了一個幾乎滿工作登錄系統,但是我的註冊頁面不能正常工作,因爲沒有什麼是對數據庫寫的,不明白爲什麼...任何想法?不工作寄存器頁面無法找到錯誤
這裏的JSP登錄頁面 「LoginPage.jsp」:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<table>
<form action="RegistraUtenteServlet" method="get">
<tr><td><b>Nome</b>
<td><input type="text" name="nomeDaRegistrare"><td></tr>
<tr><td><b>Cognome</b></td>
<td><input type="text" name="cognomeDaRegistrare"></td></tr>
<tr><td><b>Email</b></td>
<td><input type="text" name="emailDaRegistrare"></td></tr>
<tr><td><b>Username</b></td>
<td><input type="text" name="passwordDaRegistrare"></td></tr>
<tr><td><input type="submit" value="Registrati"></td></tr>
</form>
</table>
這裏的經理級 「UtentiManager.java」:
public class UtentiManager {
public void registraUtente(String nomeDaRegistrare, String cognomeDaRegistrare,String emailDaRegistrare, int tipoDaRegistrare, String passwordDaRegistrare) throws SQLException {
Connection con = DBConnectionPool.getConnection();
String query = "INSERT INTO utenti(nome,cognome,email,tipo,password) VALUES(?,?,?,?,?)";
PreparedStatement ps=con.prepareStatement(query);
ps.setString(1, nomeDaRegistrare);
ps.setString(2, cognomeDaRegistrare);
ps.setString(3, emailDaRegistrare);
ps.setInt(4, tipoDaRegistrare);
ps.setString(5, passwordDaRegistrare);
ps.executeUpdate();
ps.close();
}
}
這裏的servlet的 「RegistraUtenteServlet.java」:
public class RegistraUtenteServlet extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException, SQLException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
UtentiManager um = new UtentiManager();
String nomeDaRegistrare = request.getParameter("nomeDaRegistrare");
String cognomeDaRegistrare = request.getParameter("cognomeDaRegistrare");
String emailDaRegistrare = request.getParameter("emailDaRegistrare");
String passwordDaRegistrare = request.getParameter("passwordDaRegistrare");
int tipoDaRegistrare = 1;
um.registraUtente(nomeDaRegistrare, cognomeDaRegistrare, emailDaRegistrare, tipoDaRegistrare, passwordDaRegistrare);
} finally {
out.close();
}
}
// <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 {
try {
processRequest(request, response);
} catch (SQLException ex) {
Logger.getLogger(RegistraUtenteServlet.class.getName()).log(Level.SEVERE, null, ex);
}
}
/**
* 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 {
try {
processRequest(request, response);
} catch (SQLException ex) {
Logger.getLogger(RegistraUtenteServlet.class.getName()).log(Level.SEVERE, null, ex);
}
}
/**
* Returns a short description of the servlet.
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}
請幫幫忙!
什麼不起作用?有什麼異常?什麼是預期的和實際的行爲? –
即使像登錄和showUsers工作應用程序的其他組件,該INSERT是不行的,沒有什麼是插入分貝 – Franky