Pass JSP variable value to JAVA

Asked

Viewed 1,131 times

-1

Good afternoon,

I am using JAVA and JSP to program. I have a JSP variable and need to pass the stored value to the JAVA code.

I need to pass the variable "X" which is in index.jsp to the variable "Y" which is in the main of the indexJava.java

Someone can help me?

  • 1

    Just send the parameters on the command line that will run the program in JAVA.. JSP has the Runtime class: Runtime.getRuntime(). exec('here vc executes the command.. as if it were in a terminal, command prompt'). But logically, I don’t need to comment that the program in JAVA should be ready to receive the parameters.

2 answers

1

It depends on how you are going from JSP to Java.

If it is a simple function call between <%> or ${}, it is a normal parameter passage.

If it is a forward use the scope request.

If it is a redirect use the scope Session.

If you give more details of how your code is structured, I can improve this answer.

0

public class ServletDemo extends HttpServlet{

    private String y; 

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

            y = request.getParameter("x");
        }
}

HTML

 <!DOCTYPE html>

    <html >
        <head>
            <title>Test</title>
        </head>
        <body>

              X : <input type="text" value="" id="x" />

        </body>
    </html>

Browser other questions tagged

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