print value

Hi, I have two jsps: "1.jsp" and "2.jsp".

I am entering some data in the "1.jsp" using a

<input type="text"

then the "2.jsp" receives that data and adds it to a Cookie,

but the problem i am having is that the "2.jsp" displays the data only when I visit that page for the second time.

What I want is that the first time the page gets visited the data is displayed.

what can i do?

thanks for any response...

the code(snippet of 2.jsp):

><%

if(request.getParameter("value") !=null){

String rt = request.getParameter("value");

Cookie cookie1 =new Cookie("message", rt);

cookie1.setMaxAge(24 * 60 * 60);

response.addCookie(cookie1);

}

Cookie[] cookies = request.getCookies();

for(int loopIndex = 0; loopIndex < cookies.length; loopIndex++)

{

if (cookies[loopIndex].getName().equals("message")){

out.println("The user is: " +

cookies[loopIndex].getValue());

}

}

%>

[1534 byte] By [deroka] at [2007-11-27 6:03:32]
# 1
what can I do to solve this?
deroka at 2007-7-12 16:46:24 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Well the cookie isn't in the request the first time you access the page - because you're just adding it to the users profile now.

The easiest solution is just to print out the name in the first if statement anyway

ieif(request.getParameter("value") != null){

String rt = request.getParameter("value");

Cookie cookie1 = new Cookie("message", rt);

cookie1.setMaxAge(24 * 60 * 60);

response.addCookie(cookie1);

out.println("The user is: " + rt);

}

That will achieve your outcome, if not exactly as you may have wanted :-)

evnafetsa at 2007-7-12 16:46:24 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...