add user
[nobr]Hi,
help me with this please
I am working in this jsp-cookie issue,
and have this two .jsps: "1.jsp" and "2.jsp"
the first "1.jsp" looks like this(snippet):
It asks the user for his username, and it add it to a cookie
<form action="1.jsp" method="post" >
Username:
<br>
<input type="text" name="value">
<br><br>
<input type="submit" value="Send">
<%
if(request.getParameter("value") !=null){
String rt = request.getParameter("value");
Cookie cookie1 =new Cookie("message", rt);
cookie1.setMaxAge(24 * 60 * 60);
response.addCookie(cookie1);
}
%>
</form>
<A HREF="2.jsp"/>next</A>
the "2.jsp", basically makes a request, and if there is an available cookie, it prints it.
snippet of 2.jsp:
<%
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());
}
}
%>
what i am trying to achieve is to add another user (with the cookies), when the username is different; for example:
a user goes to the 1.jsp, enter his name"jack", then goes to the 2.jsp, and sees it displayed.
then another user goes to the 1.jsp, enter his name"marc", and sees it displayed in the 2.jsp.
so, the two names will be in two diferent cookies, and they will be "recorded"; and everytime a new user comes, the same will happen.
how can i do this?
thanks for any response...[/nobr]
[2386 byte] By [
deroka] at [2007-11-27 6:11:46]

# 2
> Cannot you add the users in the same string with some
> seperator and when reading use tokenizer.
what kind of separator?
do you have a code example?
I've been trying to do it with this other way:
there is an "if" condition to ask if the cookie1 exists, if it's true then adds the input to another cookie and tryes to read it in the "2.jsp"-
but in the 2.jsp,
its not printing diferent values/usernames,like I wanted,
its printing the same value,
how can i fix this?
<%
Cookie cookie1 = null;
if(request.getParameter("valor") != null){
String rt = request.getParameter("value");
cookie1 = new Cookie("message", rt);
cookie1.setMaxAge(24 * 60 * 60);
response.addCookie(cookie1);
}
if(cookie1 != null){
String rtq = request.getParameter("value");
Cookie cookie2 = new Cookie("message2", rtq);
cookie2.setMaxAge(24 * 60 * 60);
response.addCookie(cookie2);
}
%>
in the 2.jsp it reads:
Cookie[] cookies2 = request.getCookies();
for(int loopIndex = 0; loopIndex < cookies2.length; loopIndex++)
{
if (cookies2[loopIndex].getName().equals("message2")) {
out.println("The user is: " +
cookies2[loopIndex].getValue());
}
}
Message was edited by:
derok
deroka at 2007-7-12 17:18:17 >

# 6
> response.addCookie(cookie1 + '|' + cookie2);
>
> then when reading,
> var cookies2 = request.getCookies();
>
> var temp1 = new Array();
> temp1 = cookies2.split('|');
> ow loop temp1:
>
> temp1[0] is cookie1
> temp1[1] is cookie2
>then your if condition:
I get this error:
operator + cannot be applied to javax.servlet.http.Cookie,char
response.addCookie(cookie1 + '|' + cookie2);
^
1 error
is there another way to solve this issue?
Message was edited by:
derok
deroka at 2007-7-12 17:18:17 >
