如何将值从一个jsp传递到另一个jsp页面? [英] How to pass a value from one jsp to another jsp page?
本文介绍了如何将值从一个jsp传递到另一个jsp页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个jsp页面: search.jsp
和 update.jsp
。
I have two jsp pages: search.jsp
and update.jsp
.
当我运行 search.jsp
然后从数据库获取一个值并将该值存储在名为 scard <的变量中/ code>。现在,我想要的是在另一个jsp页面中使用该变量的值。我不想使用
request.getparameter()
。
When I run search.jsp
then one value fetches from database and I store that value in a variable called scard
. Now, what I want is to use that variable's value in another jsp page. I do not want to use request.getparameter()
.
这是我的代码:
<%
String scard = "";
String id = request.getParameter("id");
try {
String selectStoredProc = "SELECT * FROM Councel WHERE CouncelRegNo ='"+id+"'";
PreparedStatement ps = cn.prepareStatement(selectStoredProc);
ResultSet rs = ps.executeQuery();
while(rs.next()) {
scard = rs.getString(23);
}
rs.close();
rs = null;
} catch (Exception e) {
out.println(e.getLocalizedMessage());
} finally {
}
%>
我如何实现这一目标?
推荐答案
使用查询参数
<a href="edit.jsp?userId=${user.id}" />
使用隐藏变量。
<form method="post" action="update.jsp">
...
<input type="hidden" name="userId" value="${user.id}">
你可以发送使用Session对象。
you can send Using Session object.
session.setAttribute("userId", userid);
只要您的会话仍然有效,这些值现在可以从任何jsp获得。
These values will now be available from any jsp as long as your session is still active.
int userid = session.getAttribute("userId");
这篇关于如何将值从一个jsp传递到另一个jsp页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文