0

Good evening, I installed a java/tomcat webapp using servlets and jsp on an online domain. The main page is displayed, but when I go to user registration and send the data, then the first servlet starts working, the page remains blank and the url becomes domainname/ServletName. I cannot view the logs because it is a shared host and I have no idea how to fix. Thoughts or help?

This is the servlet's code

package controller;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import jakarta.servlet.RequestDispatcher;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class RegisterAdmin
 */
public class RegisterAdmin extends HttpServlet {
    private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RegisterAdmin() {
        super();
        // TODO Auto-generated constructor stub
    }
    
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        
        String name = request.getParameter("name");
        String cognome = request.getParameter("cognome");
        String user = request.getParameter("user");
        String pass = request.getParameter("password");
        
        String query = "INSERT INTO admin (nome, cognome, username, password) VALUES (?, ?, ?, ?)";
        
        try {
            Connection conn = null;
            try {
                conn = DBConnector.connect();
            } catch (Exception e) {
                e.printStackTrace();
            }
            
            PreparedStatement preparedStatement = conn.prepareStatement(query);
            preparedStatement.setString(1, name);
            preparedStatement.setString(2, cognome);
            preparedStatement.setString(3, user);
            preparedStatement.setString(4, pass);
            preparedStatement.executeUpdate();
            
            response.setContentType("text/html");
            RequestDispatcher view = request.getRequestDispatcher("index.jsp");     
            view.include(request, response); 
            try {
                if (conn != null) conn.close();
            }catch (SQLException e) {
                e.printStackTrace();
            }
            
        }catch(Exception e) {
            e.printStackTrace();
        }
        
    }

}
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • 1
    Only one idea. I once built a Java web app that was expectec to run on a operational datacenter on which as a developper I had no direct access. I decided to install a tomcat on my dev box and fully tested the app on a fully controlled environment. Only when everything worked fine on my dev box, I could give the app to the operational team.... Long strory short: install an servlet container on your dev environment and test everything there. – Serge Ballesta Jan 26 '23 at 22:03
  • Your exception handling is wrong. Any exception will this way indeed end up in a completely unhelpful blank page. See abovelinked duplicate how to properly deal with exceptions. – BalusC Jan 27 '23 at 10:35

0 Answers0