JSP information for another JSP

Asked

Viewed 223 times

0

Example: I have a JSP A, which has some information and a button. When you press this button, JSP A sends variables to B (such as id, name...). B would use this information and update the page without redirecting. There is how to do this?

2 answers

0

Hi @Thiago R.

There are some ways to do this. One of them is by form Submit.

Another would be to use JSON. You create a Javascript function that will be triggered by clicking this button, then in this function you will pass the parameters you want by JSON indicating the next page. It would look something like this:

function enviarDados() {
    $.ajax({
        url: '/paginaJSP_B',
        type: 'POST',
        contentType: false,
        data: { campo1: "abc", campo2: "XYZ" },
        dataType: 'json'
    });
}

0

all right ? Puts an excerpt of the code you are trying to do to facilitate the support you need. Without having this notion becomes more complicated help.

We will have some options depending on what you are using. Whether it is just jsp with Servlet, whether you use vraptor or some other framework. For each situation you may have a different option.

But taking into account only the logic you need, I will consider that you are using a java method that has the following behavior:

public void teuMetodo(ActionRequest actionRequest, ActionResponse actionResponse) {
   //código aqui
   actionResponse.sendRedirect("paginaQueVcQuer.jsp");//Utilize o actionResponse para redirecionar após capturar os dados que precisa no seu form.
}

Hug!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.