Passing parameter to next JSP page by a 3rd-party-Servlet-generated form
I'm trying to fix a bug in a legacy application in my organization. I need to pass an extra parameter in a dynamically generated form.
page1.jsp
<%
request.setAttribute("param", param);
// ...
%>
<form name="xx">
...
</form>
<jsp:include page="servlet1" />
The Servlet1
is calling another Servlet2
, which in turn开发者_StackOverflow社区 calls Servlet3
to print some code to page1.jsp
. The generated HTML output looks like this:
<form name="xx">
...
</form>
<form name="yy" action="page2.jsp" >
...
<input type="submit">
</form>
I need to be able to pass "param" value from page1.jsp
to page2.jsp
. The request.setAttribute()
is not working. The Servlet class Servlet3
is vendor provided, so I cannot set a hidden form variable inside form "yy" to pass it to page2.jsp
.
How can I achieve this in other way?
Your easiest bet is to use JavaScript to add a hidden input field to the form. Add the following script to the bottom of your JSP, after the point where the form is been inserted.
<script>
var input = document.createElement("input");
input.type = "hidden";
input.name = "param";
input.value = "${param}";
document.forms['yy'].appendChild(input);
</script>
You're however only dependent on whether the enduser supports JS. The only server-side alternative would be to alter the output of Servlet3
yourself with help of HttpServletResponseWrapper
.
精彩评论