如何将值从一个jsp传递到另一个jsp页面?

嗨我有两个jsp页面search.jsp,update.jsp。 当我运行search.jsp然后从数据库中获取一个值时,我将该值存储在一个名为scard的变量中,现在我想在另一个jsp页面中使用该变量值。 我不想使用request.getparameter()

这是我的代码

 

我怎么能实现这个目标?

提前致谢

使用Query参数

  

使用隐藏变量。

 
...

您可以发送使用会话对象。

  session.setAttribute("userId", userid); 

只要您的会话仍处于活动状态,现在可以从任何jsp获取这些值。

  int userid = session.getAttribute("userId"); 

使用会话

在你的search.jsp上

使用session.setAttribute("scard","scard")将你的scard放入会话中

//the 1st variable is the string name that you will reteive in ur next page,and the 2nd variable is the its value,ie the scard value.

在您的下一页中,您使用session.getAttribute("scard")检索它

UPDATE

 "/> 

使用下面的代码将字符串从一个jsp传递到另一个jsp

A.jsp

  <% String userid="Banda";%> 
<% session.setAttribute("userId", userid); %>

B.jsp

  <%String userid = session.getAttribute("userId").toString(); %> Hello<%=userid%> 

假设我们要将三个值(u1,u2,u3)从’show.jsp’传递到另一个页面,说’display.jsp’制作三个隐藏文本框和一个自动点击的按钮(使用javascript)。 //用’show.jsp’写的代码

  

//用’display.jsp’写的代码

  <% String u1 = request.getParameter("u1").toString(); String u2 = request.getParameter("u2").toString(); String u3 = request.getParameter("u3").toString(); %> 

如果你想在javascript中使用这些servlet变量,那么就简单地写一下

  

希望能帮助到你 :)