如何将参数从一个页面转发到另一个jsp页面? [英] How to forward the parameters from one page to another jsp page?

查看:305
本文介绍了如何将参数从一个页面转发到另一个jsp页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是jsp的新手,我不得不将名称从一个文件转发到另一个文件.经过大量的挖掘,我发现下面的代码可以用,但是没用.我有三个jsp文件,例如oneMain.jsp,twoMain.jsp和threeMain.jsp.我将名称threeMain从oneMain.jsp转发到twoMain.jsp.这样我就可以显示threeMain.jsp页面的内容

Am New to jsp I had to forward the name from one file to another. After a lot of dig I found the below code to be worked but it wasn't work. I have three jsp files like oneMain.jsp, twoMain.jsp and threeMain.jsp. I forward the name threeMain from oneMain.jsp to twoMain.jsp. So that I can display the content of the threeMain.jsp page

oneMain.jsp代码是

oneMain.jsp code is

<jsp:forward page="twoMain.jsp">
<jsp:param name="visualName" value="threeMain.jsp"/>
</jsp:forward>

twoMain.jsp代码是

twoMain.jsp code is

<jsp:forward page="<%= request.getParameter("visualName")%>"/>

最后,我要显示3个Main.jsp内容.

Finally I want threeMain.jsp content to be displayed.

推荐答案

请考虑以下代码,以了解如何在jsp页面之间传递参数.您可以使用<jsp:forward ... >使用以下代码转发请求:

Consider the code below on how you can pass parameters between jsp pages. You can use the <jsp:forward ... > to forward a request using this code:

<jsp:forward page="newjsp1.jsp">
  <jsp:param name="par1" value="111" ></jsp:param>
</jsp:forward>

这将使用参数par1将响应转发到newjsp1.jsp,其值为111.

This will forward the response to newjsp1.jsp with a parameter par1 and its value is 111.

现在在newjsp1.jsp中,您可以使用以下命令读取此参数:

Now in newjsp1.jsp you can read this parameter using:

<jsp:scriptlet>
  out.append(request.getParameter("par1"));
</jsp:scriptlet>

您还可以使用session隐式对象在页面之间共享属性...可能性是无限的...

You can also share attributes between pages using the session implicit Object... Possibilities are limitless...

也许您想签出这些页面:

Maybe you would like to check these pages out:

  1. http://www.tutorialspoint.com/jsp/jsp_implicit_objects.htm
  2. http://www.apl.jhu.edu/~hall /java/Servlet-Tutorial/
  1. http://www.tutorialspoint.com/jsp/jsp_implicit_objects.htm
  2. http://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/

这篇关于如何将参数从一个页面转发到另一个jsp页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆