我有一个要求,我必须重定向到另一个Web应用程序的页面,并通过查询字符串发送信息。
以下是 WEB-APP 1 的示例代码:
<html>
<body>
<form action="http://localhost:8080/WebApp2/default.htm?name=Akshay&surname=lokur">
<input type="submit" value="click me!">
</form>
</body>
</html>
当用户单击“提交”按钮时,应打开default.htm(位于另一个Web应用程序中)并应接收查询参数即。 “名和姓”。
目前,default.html已打开,但未收到任何已发送的查询参数!
答案 0 :(得分:1)
如果您尝试在html中显示请求参数,那么您可以
<html>
<body>
<form action="http://localhost:8080/WebApp2/default.jsp?name=Akshay&surname=lokur">
<input type="submit" value="click me!">
</form>
<div><%=(request.getParameter("name")!=null?request.getParameter("name"):"")%></div>
</body>
</html>
发生了什么事?
<%
&amp; %>
是java scriplets的标签。(条件?语句如果为真:语句如果为假)
是ternary if,类似于:
if(<condition>){ statement if true; }else{ statement if false; }
(request.getParameter("name")!=null?request.getParameter("name"):"")
变得类似于:if(request.getParameter("name")!=null){ request.getParameter("name"); }else{ ""; }
<强> = 强>
只是在那里显示条件结果
我希望能帮助你。
编辑:刚刚注意到你没有使用jsp(为什么?假设你要显示发布的数据)。将我的版本更改为jsp,因为这是我们在html中显示请求参数的唯一方式。
答案 1 :(得分:0)
这看起来应该对我有用。是什么让你觉得参数没有发送?我建议在安装了Firebug的Firefox中加载您的页面,然后单击Firebug并查看网络选项卡。然后单击您的提交按钮,您将能够在网络面板中看到已发送的参数。如果您可以验证发送的参数可能比您在其他服务器上检查它们的方式不起作用。