Пустая страница приходит в качестве вывода
Цитата:я пытаюсь вставить сведения о сотруднике в базу данных sql но когда я запускаю программу она показывает страницу регистрации после ввода сведений вывод не отображается как пустая страница
Что я уже пробовал:
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"> <servlet> <servlet-name>CreateServlet</servlet-name> <servlet-class>com.sai.CreateServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>CreateServlet</servlet-name> <url-pattern>/CreateServlet</url-pattern> </servlet-mapping> <session-config> <session-timeout> 30 </session-timeout> </session-config> </web-app>
public class CreateServlet extends HttpServlet { protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); Connection con=null; Statement st=null; try { Class.forName("com.mysql.jdbc.Driver"); DriverManager.getConnection("jdbc:mysql://localhost:3306/dbemployee","root",""); con.createStatement(); String id=request.getParameter("UserName"); String pwd=request.getParameter("Password"); String eAdd=request.getParameter("EmpAddress"); String gender=request.getParameter("MaleorFemale"); String email=request.getParameter("Email"); String lang=request.getParameter("languages"); String nation=request.getParameter("Nationality"); String date=request.getParameter("RegDate"); String sql="insert into Employee Values ('"+id+"' '"+pwd+"' '"+eAdd+"' '"+gender+"' '"+email+"' '"+lang+"' '"+nation+"' '"+date+"')"; st.executeUpdate(sql); if(id !=null | pwd != null | eAdd!=null | gender !=null |email !=null | lang !=null | nation!=null | date !=null) { RequestDispatcher rd = request.getRequestDispatcher("/success.html"); rd.forward(request, response); } else { out.println("<font color=red>Please fill all the fields</font>"); RequestDispatcher rd = request.getRequestDispatcher("/index.html"); rd.forward(request, response); } }catch(ClassNotFoundException | SQLException | NullPointerException e) { e.printStackTrace(); } finally { try { if(st!=null) st.close(); if(con!=null)con.close(); } catch(Exception e) { e.printStackTrace(); } } } // <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); } /** * Returns a short description of the servlet. * * @return a String containing servlet description */ @Override public String getServletInfo() { return "Short description"; }// </editor-fold> }