- function operation(){
- var frm = document.getElementById("frm");
- frm.action="second.jsp? n1="+<%=newname%>;
- }
- some jsp code.
- <form name="frm" method="post">
- <%=String newname=name[i]%>
- .
Keeping this in consideration, how do I pass a variable from one JSP to another?
Can be done in three ways:
- using request attributes: Set the value to send in request attribute with a name of your choice as request.setAttribute("send", "valueToSend") and retrieve it on another jsp using request.getAttribute("send");
- using session attributes.
- using application attributes.
One may also ask, how use javaScript variable in JSP code? Your javascript values are client-side, your scriptlet is running server-side. So if you want to use your javascript variables in a scriptlet, you will need to submit them. To achieve this, either store them in input fields and submit a form, or perform an ajax request. I suggest you look into JQuery for this.
Secondly, how do I transfer data from one JSP page to another?
Detail : The values which are to be sent from source jsp are set using setAttribute() method of request object which takes the name of attribute as first argument and the value of attribute as the second argument. The name of attribute can be any user defined string.
Can we use javaScript in JSP?
Yes, We can use javaScript with JSP page. As we know that javaScript is a Client-side script and JSP is a Server-side so we can attach a form validation to a JSP page to redirect HTML page and javaScript content.
