I am new in JSP, i have a question, i have a jsp page in this there are hiperlink, after clicking link it navigate to def.jsp page.
我是JSP的新手,我有一个问题,我有一个jsp页面,这里有hiperlink,点击链接后导航到def.jsp页面。
issue :- i want send this person object to def.jsp page
问题: - 我想将此人物对象发送到def.jsp页面
Abc.jsp
<a href = "/def.jsp"><%person.getFirstName()%></a>
NOTE:- i am not getting request reference in a tag and cann't send any object from query string as i know.
注意: - 我没有在标签中获取请求引用,并且不能像我所知的那样从查询字符串发送任何对象。
if my question is clear to you, please response me.
如果我的问题很清楚,请回复我。
3 个解决方案
#1
0
if the object is just between these two pages.. then you can use <%request.setAttribute("person",person);%>
this would add the person object to the request & can be accessed as
如果对象就在这两个页面之间..那么你可以使用<%request.setAttribute(“person”,person);%>这会将person对象添加到请求中并且可以作为
<% Person p = (Person)request.getAttribute("person");%>
name is <b><%=p.getFirstName()%></b>
else you can put the person object in the session.. session.setAttribute(Stirng, Object)
& session.getAttribute(String)
否则你可以把person对象放在会话中.. session.setAttribute(Stirng,Object)&session.getAttribute(String)
#2
0
You do not pass an object, but parameters as string values.
您不传递对象,而是传递参数作为字符串值。
A valid URL would be
有效的URL将是
/def.jsp?firstName=Prabhat
That would allow, in the receiving JSP, to ask for parameter "firstName" and get back "Prabhat".
这将允许在接收JSP中请求参数“firstName”并返回“Prabhat”。
Note that you should use URLEncode in your parameters in case they may have special characters (including whitespace).
请注意,您应该在参数中使用URLEncode,以防它们具有特殊字符(包括空格)。
Also, the '<%' tag is used to include java code, not to output. Your code is equivalent to:
此外,'<%'标记用于包含java代码,而不是输出。您的代码相当于:
out.println("<a href = \"/def.jsp\">);
person.getFirstName();
....
For "printing" the variable value, you should use '<%='
要“打印”变量值,您应该使用'<%='
#3
0
I suppose this is what you wants to do
我想这就是你想要做的
Abc.jsp
<a href = "/def.jsp?pName=<%=person.getFirstName()%>"></a>
def.jsp
<%
String personName = request.getParameter("pName");
%>
Person Name:<%=personName%>
#1
0
if the object is just between these two pages.. then you can use <%request.setAttribute("person",person);%>
this would add the person object to the request & can be accessed as
如果对象就在这两个页面之间..那么你可以使用<%request.setAttribute(“person”,person);%>这会将person对象添加到请求中并且可以作为
<% Person p = (Person)request.getAttribute("person");%>
name is <b><%=p.getFirstName()%></b>
else you can put the person object in the session.. session.setAttribute(Stirng, Object)
& session.getAttribute(String)
否则你可以把person对象放在会话中.. session.setAttribute(Stirng,Object)&session.getAttribute(String)
#2
0
You do not pass an object, but parameters as string values.
您不传递对象,而是传递参数作为字符串值。
A valid URL would be
有效的URL将是
/def.jsp?firstName=Prabhat
That would allow, in the receiving JSP, to ask for parameter "firstName" and get back "Prabhat".
这将允许在接收JSP中请求参数“firstName”并返回“Prabhat”。
Note that you should use URLEncode in your parameters in case they may have special characters (including whitespace).
请注意,您应该在参数中使用URLEncode,以防它们具有特殊字符(包括空格)。
Also, the '<%' tag is used to include java code, not to output. Your code is equivalent to:
此外,'<%'标记用于包含java代码,而不是输出。您的代码相当于:
out.println("<a href = \"/def.jsp\">);
person.getFirstName();
....
For "printing" the variable value, you should use '<%='
要“打印”变量值,您应该使用'<%='
#3
0
I suppose this is what you wants to do
我想这就是你想要做的
Abc.jsp
<a href = "/def.jsp?pName=<%=person.getFirstName()%>"></a>
def.jsp
<%
String personName = request.getParameter("pName");
%>
Person Name:<%=personName%>