Pass variable value from JSP to JAVA

0

Good afternoon,

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

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

Can someone help me?

    
asked by anonymous 19.06.2014 / 18:00

2 answers

1

Depends on how you are going from JSP to Java.

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

If it's a forward, use the request scope.

If it is a redirect , use the session scope.

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

    
19.06.2014 / 20:09
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>
    
03.12.2015 / 16:59