I have one JSP file as jsp 1.jsp and another JSP file as jsp 2.jsp
I\'ve included jsp 2.jsp in jsp 1.jsp
You can set a jsp:param
, as in this example jsp:param element or take a look at this similar post Passing parameters between JSP pages.
in jsp1 use this way to pass value.
<form action="">
<input type="hidden" name="hidden" value="hidden">
<input type="submit" value="submit"></form>
in jsp2 to get value
String value=request.getParameter("hidden");
Try to use Ajax with JQuery
to achieve your goal or you can simply store the String object in session
and you can delete it in jsp2.jsp
when ever you use it. or you can simply append to a url
as query string
there are multiple ways among them the above are few.
These questions may help you
Question 1
Question 2
Question 3
Question 4
If the reason for including your jsp 2
in jsp 1
is for sending variable, then its not needed
.
you just need to set a hidden
variable in jsp 1
, and in your jsp 2
you should able to access it, by using the jsp implicit request
object.
You have a number of options:
Store it in the session.
// Memorise any passed in user.
String username = request.getParameter("username");
if (username != null && username.length() > 0) {
session.setAttribute("username", username);
}
Store it as a hidden field in the form.
<input name="username" type="hidden" value=""/>
Store it in a cookie.
username = getCookie(userCookieName);
// Get from cookie.
function getCookie(name) {
if (document.cookie) {
index = document.cookie.indexOf(name);
if (index !== -1) {
f = (document.cookie.indexOf("=", index) + 1);
t = document.cookie.indexOf(";", index);
if (t === -1) {
t = document.cookie.length;
}
return(document.cookie.substring(f, t));
}
}
return ("");
}
Persist it on the client side in sessionStorage. See here for details.
sessionStorage.setItem("username", "...");
Not really another option but a mechanism - pass it in the URL:
.... onclick="window.location='details.jsp?username=...'