access hidden field value into another jsp file
i've a hidden field value
<input type="hidden" id= "i1" name="h1" val开发者_StackOverflow中文版ue="Request Recieved"/ >
i need the value to be read in another jsp file whose reference is mentioned in the current file.
i'm using out.println(request.getParameter("h1"));
but its printing null..
This will only work when you navigate to another JSP by a <form>
which has this field embedded.
E.g. page1.jsp
:
<form action="page2.jsp">
<input type="hidden" name="foo" value="bar">
<input type="submit">
</form>
And page2.jsp
:
<p>Hidden value: ${param.foo}</p>
That's all. It won't work when you navigate by a link <a>
or submit another form where the hidden field is not included.
(the ${param.foo}
does effectively the same as out.print(request.getParameter("foo"))
, only in a less vintage and ugly manner. See also How to avoid Java code in JSP)
精彩评论