如何在两个jsp页面之间传递字符串? [英] How to pass a string between two jsp pages?
本文介绍了如何在两个jsp页面之间传递字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在我的两个jsp页面之间传递一个字符串(用户名),
I want to pass a string(username) between my two jsp pages,
Login.jsp和Details.jsp.
Login.jsp and Details.jsp.
请告诉我们该怎么做?
I tries this in Login.Jsp
<html>
......
<%
session.setAttribute("key","value");
%>
.....
</html>
In Details.jsp
<html>
......
<%
session.getAttribute("key");
%>
.....
</html>
It showed "NULL" as output.
推荐答案
有几种方法可以将数据从一个网页传递到另一个网页:
There are several ways to pass data from one webpage to another:
- 在Login.jsp上放置一个表单,然后将其发布到Details.jsp.这会将表单中的值发布到Details.jsp.
- 重定向到
Details.jsp?username=ARJUN
.这将在查询字符串中将一个变量传递给Details.jsp. - 将用户名放在Cookie中.该cookie将被提交到Details.jsp(以及其他所有页面),从而可以确定每个页面中的用户名.
- 将用户名放入会话中.类似于Cookie,但会话存储在服务器上并与当前正在查看您的网站的用户相关联.
- Put a form on Login.jsp and let it post to Details.jsp. This will post the values in the form to Details.jsp.
- Redirect to
Details.jsp?username=ARJUN
. This will pass a variable to Details.jsp in te query string. - Put the username in a cookie. The cookie will be submitted to Details.jsp (and every other page), which makes it possible to determine the username in every page.
- Put the username in the session. Similar to a cookie, but the session is stored on the server and associated with the user that is currently viewing your website.
这篇关于如何在两个jsp页面之间传递字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文