开发者

How to send object from a tag

I am new in JSP, i have a question, i have a jsp page in 开发者_JAVA技巧this there are hiperlink, after clicking link it navigate to def.jsp page.

issue :- i want send this person object to def.jsp page

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.


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

<% 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)


You do not pass an object, but parameters as string values.

A valid URL would be

/def.jsp?firstName=Prabhat

That would allow, in the receiving JSP, to ask for parameter "firstName" and get back "Prabhat".

Note that you should use URLEncode in your parameters in case they may have special characters (including whitespace).

Also, the '<%' tag is used to include java code, not to output. Your code is equivalent to:

 out.println("<a href = \"/def.jsp\">);
 person.getFirstName();
 ....

For "printing" the variable value, you should use '<%='


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%>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜