0

Hello , I am new to jsp as well to wml too .. Problem is with Session variable . the page on which session variable are made , they are extracting on that page easily .... but on other pages ...they contain null values ...i am not able to get proper values .

function used to set and extract session values :

session.setAttribute("sessumobile", user1);

<p>Name : <%=session.getAttribute("sesspassword")%></p> respectively //used on next page .

please help me out ...

thanx in advance ...

2
Contributors
13
Replies
16
Views
6 Years
Discussion Span
Last Post by mayursharma
0

hello javaAddict , thaanx for immediate reply ... but i dont get u .Spry

For more clearance : I have set both username and its password as session variable.And try to get these variabl;e on another page ... but it is no happening .

//On Page1.jsp
session.setAttribute("sessumobile", user1);
session.setAttribute("sesspassword",pass1 );
//On page2.jsp
<%=session.getAttribute("sesspassword")%>
<%=session.getAttribute("sessuser1")%>

0

You get the "sesspassword" because you set it:

//On Page1.jsp
session.setAttribute("sesspassword",pass1 );

//On page2.jsp
<%=session.getAttribute("sesspassword")%>

But do you set the sessuser1? I see that you only do:
<%=session.getAttribute("sessuser1")%>
Where do you set it?

Also if sesspassword "returns" null:
1) are you sure the code where you set its value executes?
2) are you sure that you didn't misspell the sesspassword? (sesspasword/sespassword ) they both need to be the same.
3) are you sure that the value that you set (pass1) is not null?

Try to add some messages (System.out.println) that print at the server and see.

0

yeah ... i hav olready chek the above 3 pints .. I hav recheked olso . Its oll okay .
And Sory... My last line in my previous post is wrongly written : it is-

<%=session.getAttribute("sessumobile")%
And i m not getting both sessumobile and sesspassword on next page .!!

Dont know what is going wrong !!

0

My page 1:

<%@page contentType="text/vnd.wap.wml;charset=ISO-8859-1"  %>
<?xml version="1.0" ?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wepforum.org/DTD/wml_1.1.xml" >

<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<wml>
	<card id = "one"  title  ="Processing">
<%
	String user1 = request.getParameter("umobile");
	String pass1 = request.getParameter("password");	
	out.print(user1);
	out.print(pass1);

try{
	Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		Connection connection=DriverManager.getConnection("jdbc:odbc:llms","administrator","mayur07");
		String query = "SELECT * FROM ADMINISTRATOR.USERDATA WHERE userid = "+user1+" AND upass ='"+pass1+"'";
		Statement stmt = connection.createStatement();
		ResultSet resp =stmt.executeQuery(query);
		int count=0;
		while(resp.next()){
			if(count==0){
				count++;
				out.print("Successfully Logged In  :) ");
			}				
		}
		
	} catch(Exception se){
			out.println("<br><font size = \"+1\" color = \"red\">Oops! The server could not process your request!");
			se.printStackTrace(new PrintWriter(out));
	  }
				session.setAttribute("sessumobile", user1);
				session.setAttribute("sesspassword",pass1 );
				out.print(session.getAttribute("sessumobile").equals(""));
				out.print(session.getAttribute("sessumobile"));
				out.print(session.getAttribute("sesspassword").equals(""));
				out.print(session.getAttribute("sesspassword"));
%>
			<onevent type="ontimer">
					<go href="session_var2.jsp"/>
				</onevent>
				<timer value="20"/>
</card>
</wml>
0

My page 2 :

<%@page contentType="text/vnd.wap.wml;charset=ISO-8859-1" session="true" %>
<?xml version="1.0" ?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wepforum.org/DTD/wml_1.1.xml" >

<%@page import="java.sql.*"  %>
<%@page import="java.io.*"%>
<% String user1 = request.getParameter("umobile"); %>
<wml>
<card id = "one" title ="chek">
<p>Hello</p>
<% out.print("hellooo1");
%>
<p>Name  : <%=session.getAttribute("sessumobile")%></p>
<p>Name  : <%=session.getAttribute("sesspassword")%></p>
<% out.print("hellooo");%>
</card>
</wml>
0

The query should be like this: "SELECT * FROM ADMINISTRATOR.USERDATA WHERE userid = '"+user1+"' AND upass ='"+pass1+"'" Not: "SELECT * FROM ADMINISTRATOR.USERDATA WHERE userid = "+user1+" AND upass ='"+pass1+"'" After the execution of the query you always go to the second page. You don't check if the log in was successful. You execute the query and the without checking the result you go to the second page.

Also. Delete most of your code and:
Write a separate class with a method that connects to the database, executes the query, returns the result and CLOSES everything (ResultSet, Statement, Connection).
Don't put that "database connection code" there. Put it in a separate class and call a method that simply returns true/false if the log in was successful.
Then if it is true, only then redirect.

The above is general practice and you should follow it!

As for the session, it should return what you set it, but I am not familiar with wml, so you might want to wait for someone else to reply.

Edited by javaAddict: n/a

0

Thaanx JavaAddict.. i understand the general rule .. i'll definetely do that , but as far as my problem is concerned ....if out.print(session.getAttribute("sessumobile")); is giving output on mypage1.jsp ... then why it is not comming in mypage2.jsp ...as this function is nothing but retreiving data from session itself .!!

Any reason for this .??

0

I have tried that too... it gives the same result ... !! null on the seecond page .

0

Maybe somehow, you are losing the session. You might want to check some tutorials about sessions in wml and what this tag does:
<onevent type="ontimer">
<go href="session_var2.jsp"/>
</onevent>

Is there any other way to go from one page to the next?

Try to use <go href="session_var2.jsp"/> ONLY, without the onevent

Edited by javaAddict: n/a

0

hmm... How can i get this right but ... if session variable will not work , how can i move on ... please ... somebody help me to get out of this error ...!!

0

i have used
<a href = "session_var2.jsp">Goo</a>

but it still outputting null there ..!!

And <go href="session_var2.jsp"/> is not working there .

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.