简体   繁体   English

通过3rd-party-Servlet生成的表单将参数传递到下一个JSP页面

[英]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 calls Servlet3 to print some code to page1.jsp . Servlet1正在调用另一个Servlet2 ,后者又调用Servlet3将一些代码打印到page1.jsp The generated HTML output looks like this: 生成的HTML输出如下所示:

<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 . 我需要能够将“ param”值从page1.jsppage2.jsp The request.setAttribute() is not working. request.setAttribute()无法正常工作。 The Servlet class Servlet3 is vendor provided, so I cannot set a hidden form variable inside form "yy" to pass it to page2.jsp . Servlet类Servlet3由供应商提供,因此我无法在表单“ yy”内设置隐藏的表单变量以将其传递给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. 最简单的选择是使用JavaScript向表单添加隐藏的输入字段。 Add the following script to the bottom of your JSP, after the point where the form is been inserted. 在插入表单的位置之后 ,将以下脚本添加到JSP的底部。

<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. 但是,您仅取决于最终用户是否支持JS。 The only server-side alternative would be to alter the output of Servlet3 yourself with help of HttpServletResponseWrapper . 唯一的服务器端替代方法是在HttpServletResponseWrapper帮助下自行更改Servlet3的输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM