0

Creating session

asked 2006-04-13 06:06:46 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3684190

By: nobody

Hello,

In a function i have written following code for seting session attribute

(Sessions.getCurrent()).setAttribute(UserName,name.value);
(Sessions.getCurrent()).setAttribute(Language,CmbLang.value);
alert( "Welcome :"+ rs.getString("LSU_USER_NAME_C"));
alert((Sessions.getCurrent()).getAttribute(UserName));
Executions.sendRedirect ("Session2.zul");


it is displaying user name properly but in session2.zul

i have written code to extract UserName attribute as follows:- B.value=(String)(Sessions.getCurrent()).getAttribute(UserName);

but here i am getting blank value Please kindly tell me how to correct this code. I have written that much code only for creating session.


delete flag offensive retag edit

9 Replies

Sort by ยป oldest newest

answered 2006-04-13 13:14:50 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3684775

By: henrichen

It should work.

What is UserName? Where is the UserName come from in the session2? Please provide a "reduced" zuml code and it would be easier for us to replicate the bug.

/henri

link publish delete flag offensive edit

answered 2006-04-18 09:21:59 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3691806

By: tanya20

session attribute not working properly.

Login.zul

try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection(url,"Employee","employee123");
Statement st=con.createStatement();

String pwdquery="Select user_id,pwd From employee where LSU_USER_ID_C = '"+name.value+"'";
ResultSet rs=st.executeQuery(pwdquery);
String DbPasswd;

if(rs.next())
{
DbPasswd=rs.getString("LSU_ENCRYPTED_PASSWD_C");

if(DbPasswd.equals(Pass))
{

(Sessions.getCurrent()).setAttribute(name,name.value);
alert((Sessions.getCurrent()).getAttribute(name));
Executions.sendRedirect ("Sess_log_1.zul");
}
else
{

alert("UserId/Password is Incorrect");
clear();

}
}

con.close();
}catch(SQLException error)
{
alert("Sql Error");
}


in Sess_log_1.zul

String name;
B.value=(String)(Sessions.getCurrent()).getAttribute(name);


but its not working i am getting null value for name in Sess_log_1.zul but in Login.zul alert((Sessions.getCurrent()).getAttribute(name)); is displaying the user name.

Plaese tell how to create session if the way i am doing is wrong.

link publish delete flag offensive edit

answered 2006-04-18 11:14:32 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3691939

By: tomyeh

Did you mean setAttribute("name", name.value) and getAttribute("name")?

BTW, you seem forget to close connection at the finally clause:)

link publish delete flag offensive edit

answered 2006-04-18 11:28:52 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3691957

By: tanya20

i tried even after changing setAttribute("user",name.value) and getAttribute("user")

and i am closing connection just before end of try block.

link publish delete flag offensive edit

answered 2006-04-18 12:35:28 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3692047

By: tomyeh

Closing connection at try block is not good enough. For example, a NullPointerException makes the connection remaining open.

ZK's session is simple wrap of HttpSession. You might take a look at the source
codes: com.potix.zk.ui.http.SessionImpl.

BTW, what Web server do you use?

link publish delete flag offensive edit

answered 2006-04-18 12:54:47 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3692101

By: henrichen

Change your code a little bit:

Login.zul

...

(Sessions.getCurrent()).setAttribute("user",name.value);
alert((Sessions.getCurrent()).getAttribute("user"));

...


in Sess_log_1.zul

B.value=(String)(Sessions.getCurrent()).getAttribute("user");


Session attribute is in fact a Map. You have to provide same _KEY_ to fetch that value.

/henri

link publish delete flag offensive edit

answered 2006-04-19 04:08:14 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3693335

By: tanya20

Thanks Tom , i am using Tomcat 5.5 u aksed me to see the source codes but no code is availble thr only declartaion of classes and functions are available from where i can find the whole code.



link publish delete flag offensive edit

answered 2006-04-19 04:09:45 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3693339

By: tanya20

Thanks henri,

Now session is working properly.

link publish delete flag offensive edit

answered 2006-04-19 05:46:59 +0800

admin gravatar image admin
18691 1 10 130
ZK Team


Orignial message at:
https://sourceforge.net/forum/message.php?msg_id=3693399

By: henrichen

Glad to know your problem solved.

/henri


link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2006-04-13 06:06:46 +0800

Seen: 746 times

Last updated: Apr 19 '06

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More