How to open a JSP inside a JSP through a Servlet?

Posted on

Question :

I’m using a Script, but I’m not using Servlet to do the desired action inside my index.jsp page, and do not use this Script below to open a JSP file inside my index.jsp home page.

  <script src="//"></script>

        $(document).ready(function() {
            var domContent = $("#content");

            $(".nav-link").click(function() {
                return false;

<li class="topmenu"><a class="nav-link" href="cad_conta.jsp" title="Cadastrar uma conta" style="height:19px;line-height:19px;">Cadastro</a></li>
  • I already have a class Servlet() with method doGet() and doPost() .
  • Within my Servlet() class, can I open a JSP file on my home page without having to use a Script JQuery using some method within the Servlet() class?
  • Answer :

    The correct one in a web application is always to create a class servlet every jsp created, to deal with your requests and answers.

    In your case you already have a servlet , you should create a new servlet corresponding to the jsp you want to call, examples: jspCadastro , ServletCadastro .

    As for the method, you can create a doGet method that will be responsible for calling your jsp using RequestDispacher .

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    req.getRequestDispatcher("/WEB-INF/paginas/jspCadastro.jsp").forward(req, resp);

    In your main%% of%, you only add a button by passing the path of your jsp responsible for that servlet . Example:

    <button onclick="window.location=' ServletCadastro '">Cadastrar</button>

    calling its jsp by method servlet through doGet .


    Leave a Reply

    Your email address will not be published. Required fields are marked *